Testing of a String.|String methods|

A string may contain digit, alphabet or combination of both of this. This various methods are available to test if the entered string is digit or alphabets or alphanumeric.

bool isalnum:

str=input("enter string") print(str) print(str.isalnum())

output:

enter string:harsh harsh True

bool isalpha:

str="123python" str1="python" print(str.isalpha()) print(str1.isalpha())

output:

False True

bool isdigit:

str="123" str1="python" print(str.isdigit()) print(str1.isdigit())

output:

True False

bool islower:

str="PYTHON" str1="python" print(str.islower()) print(str1.islower())

output:

False True

bool isupper:

str="PYTHON" str1="python" print(str.isupper()) print(str1.isupper())

output:

True False

bool isspace:

str=" " str1="python" print(str.isspace()) print(str1.isspace())

output:

True False

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.