String function in python

technical talkiess
0

 print("String function in python")

str1 = "this is the string"

# if you want to get length of the string

print(len(str1))


# slicing thr string .... its return the 0 to 17 character .... 0 is include and 18 is exclude 

print(str1[0:18])

# slicing thr string .... if you want skip 2 character in the string you add 3 parameter in the function 

print(str1[0:19:2])

# slicing thr string .... if you want to return the last elenment you can put in - value  

print(str1[:-5])

# slicing thr string .... if you want to first letter upparcase the string 

print(str1.capitalize())

# slicing thr string .... if you want to upparcase the string 

print(str1.upper())

# slicing thr string .... if you want to check string ends with 

print(str1.endswith("string"))

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)