Friday, 19 February 2021

Python String Method


>>> S="Hello"

>>> S.upper()

'HELLO'

>>> S.lower()

'hello'

>>> len(S)

5

>>> S="hello india"

>>> S.capitalize()

'Hello india'

>>> S.isspace()

False

>>> S=" "

>>> S.isspace()

True

>>> S="hello india"

>>> len(S)

11

>>> S=""

>>> S.isspace()

False

>>> S=" "

>>> S.isspace()

True

>>> S="        "

>>> S.isspace()

True

>>> S="A     "

>>> S.isspace()

False

>>> S=""

>>> S.isalnum()

False

>>> S=" "

>>> S.isalnum()

False

>>> S="123"

>>> S.isalnum()

True

>>> S="abc123"

>>> S.isalnum()

True

>>> S="a$2"

>>> S.isalnum()

False

>>> S="Ram Kumar"

>>> S.isalnum()

False

>>> S="abc"

>>> S.isalnum()

True

>>> S=""

>>> S.isalpha()

False

>>> S1="123"

>>> S1.isalpha()

False

>>> S2="abc"

>>> S2.isalpha()

True

>>> S3="abc123"

>>> S3.isalpha()

False

>>> S4="12"

>>> S4.isalnum()

True

>>> S5="1.2"

>>> S5.isalnum()

False

>>> S="Ram Kumar Sharma"

>>> B="Kumar"

>>> S.find(B)

4

>>> C="kumar"

>>> S.find(C)

-1

>>> D="m"

>>> S.find(D)

2

>>> S.find(D,3)

6

>>> S.find(D,6,14)

6

>>> S.find(D,7,14)

-1

>>> len(S)

16

>>> S.find(D,7)

14

>>> S.find(D,S.find(D)+1)

6

>>> A="   Ram"

>>> print(A)

   Ram

>>> print(A.lstrip())

Ram

>>> A

'   Ram'

>>> A.lstrip()

'Ram'

>>> A="AAAARam"

>>> A.lstrip('A')

'Ram'

>>> A="BBBBHello"

>>> A.lstrip('B')

'Hello'

>>> A="Amarjeet Kumar"

>>> A

'Amarjeet Kumar'

>>> A.lstrip()

'Amarjeet Kumar'

>>> A.lstrip('Amar')

'jeet Kumar'

>>> A="Ram      "

>>> A.rstrip()

'Ram'

>>> A="Amarjeet Kumar"

>>> A.rstrip(' Kumar')

'Amarjeet'

>>> A='k'

>>> ord(A)

107

>>> A='B'

>>> ord(A)

66

>>> chr(65)

'A'

>>> chr(97)

'a'

>>> A="Hello India"

>>> A.swapcase()

'hELLO iNDIA'

>>> A="S P SHARMA CLASSES"

>>> A.partition(' ')

('S', ' ', 'P SHARMA CLASSES')

>>> A="IndiaHelloDelhi"

>>> A.partition('Hello')

('India', 'Hello', 'Delhi')

>>> A="   Ram    "

>>> A.strip()

'Ram'

>>> A="S P SHARMA CLASSES"

>>> A.partition('P ')

('S ', 'P ', 'SHARMA CLASSES')


No comments:

Post a Comment