String in Python | Function related to string in Python
Initializing string in Python X = "some string" or X = 'some string' print(x) Getting character at a specified position X = "some string" Y = X[0] # position in big brackets 1 st character is treated as 0th position print(Y) For getting character from back we have to mention -ve sign z = X[-1] print(z) Getting a set of character from string For getting a set of a character from index a to index b we have to use X= "some string" Y = X[a:b] # b will be excluded Y = X[5:8] Getting length of string X = "some string" Y = len(X) print(y) Converting text into lower case or upper case using x.lower() X = "SOME string" y=x.lower() print(y) Using x.upper X = "some string" Y = x.upper print(y) Removing space from start or end of a string Using strip X = " some str...



Comments
Post a Comment