String Slicing in Python.

 a="faizan is a good boy"

print(a[3:9])    #in this the range between number is only displayed 

print(len(a))     #in this the number of sent is  displayed in result

print(a[0:64])    #since there is no 68 words in sent therefore it will print whole sent

print(a[0:5:2])   #0 sai 5 k bich mai 2 ka gap rakh k yai word lega

print(a[ : : ])   #isme sub copy karega

print(a[ : :-1])   #isme bhi  sub print karega but  in opposite way

print(a[ : :33341343])  #phele yai zero lega uske bad 33341343 aage  jayega dekha kuch nhi hia .sirf 0 word aayega

print(a[-4: :-4])  #minus mai piche sai counting start hota hai with one not zero

print(a.endswith("boy"))   #it say does it contain the given word or  not

print(a.count("a"))    #it will count number of a in sent

print(a.capitalize())   #it will capital the first word

print(a.find("is"))  #it will find position of is

print(a.upper())  #it will convert whole sent in upper case for  small letter use (lower)

print(a.replace("is","you")) #in sent it will convert is in you

#search in google  -string function in python for more info

Comments