Saturday, 16 March 2019

string manipulation class 11 cbse

STRING MANIPULATION

STRING CREATION
  • By assigning value direct to the variable
>>> str ="I love myself"
>>> str
I love myself
  • By taking input
>>> str= input("enter a number")
     Enter a string This is python
>>> str 
     This is python

Transverse of a string

string1= input("Enter a string:")
print("The",string1,"in reverse order is:")
length= len(string1)
for a in range (-1,(-length),-1))
      print(sting1[a])

Membership operator in a string.

  • in operator result into True or False.
like= "a" is in "pradeep"will result into true.
  • not in
"k" not in "kumar" will result false.

String comparison operators

upper case and lower case has different unicode value.
EX. "A"=="a" false
       "abc"=="ABC" false
       "b"=="b" true

How to get unicode/ Ordinal value

>>>ord('a')
   97
>>>ord('A')
   65
>>> char(97)
   A

No comments:

Post a Comment