Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #String Operations
- #-----------------
- fname='boka'
- lname='manush'
- name=fname+' '+lname+'\n'
- print(name)
- print(name*3) #it will print 3 times
- #String Length
- #--------------
- strLength = len(name)-1
- print(strLength)
- #String Indexing
- #-----------------
- print(name[3])
- #String Methods
- #-----------------
- print(name.upper()) #all capital
- print(name.lower())
- print(name.capitalize())
- print(name.count('a'))
- print(name.split('n')) #split when it will get n
- #String Splicing [n:m] including n,excluding m
- #---------------------------------------------
- print(name[2:7]) #trim 2nd to 7th chacter
- print(name[3:])
- print(name[:3])
- print(name[3:-2]) #start from 3rd and also delete last 2 character
- #String Comparison
- #----------------
- print(fname==lname) #if equal return true else false
- print(fname<lname)
- print(ord('U')) #Ordinal Value of U (Ascii value)
- print(ord('u')) #lower U
- print(chr(85))
- print('Ni' in 'Nihal') #retun true if Ni is in Nihal
- print('ni' in 'Nihal') #it will return false. case ni is small
- print('Boka' not in 'BokaImon') #it will return false. cause it is in
- #String Traversal with Loop
- #--------------------------
- #using for Loop
- aString ='bristi pore tapur tupur kuratoli te elo ban,shib thakurer biye holo tin konne dan'
- for bristipore in aString:
- print(bristipore)
- print('--------------------------------')
- #write a program to extract all a in l character from a given string
- newStr = 'hello my friend alal,now die!'
- for test in newStr:
- if(test=='a' or test== 'l'):
- print(test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement