Social Media

1/02/2019

More functions of String

list(): String can be converted to list using list() method.
s="mayank kumar"
l=list(s)
print(l) # ['m', 'a', 'y', 'a', 'n', 'k', ' ', 'k', 'u', 'm', 'a', 'r']

isalnum(): This function returns True if all the characters of string are A-Z, a-z or 0 to 9, else return False.
s="sm32"
print(s.isalnum()) #True

isdigit(): This function returns True if all the characters of string are 0 to 9.
s="0383m"
print(s.isdigit()) # False

isalpha(): This function returns True if all the characters of the string are A -Z or a-z.
s="mayank"
print(s.isalpha()) # True

isupper(): This function returns True if all the letters of string are in capital letters.
s="MAYANK"
print(s.isupper()) #True

islower(): This function returns True if all the letters in the string are in lower case.
s="mayank"
print(s.islower()) # True
Be First to Post Comment !
Post a Comment