isalpha, isdigit and isalnum functions in python

we can check whether any string is consist of alphabet or numeric or both in python.
let's learn each function one by one
str.isalpha()
this function will return true if all characters in the string are alphabet. otherwise, return false.
str.isdigit()
this function will return true if all characters in the string are digit. otherwise, return false.
str.isalnum()
this function is combined with isdigit and isalpha. if all characters are digit number or alphabet, this function will return true. otherwise return false.

you can learn them well from code.


str1 = "python"
str2 = "python "
str3 = "123"
str4 = "python3"
str5 = "python3.7"

print('"python" -> isalpha: {}, isdigit: {}, isalnum: {}'.format(str1.isalpha(), str1.isdigit(), str1.isalnum()))
print('"python " -> isalpha: {}, isdigit: {}, isalnum: {}'.format(str2.isalpha(), str2.isdigit(), str2.isalnum()))
print('"123" -> isalpha: {}, isdigit: {}, isalnum: {}'.format(str3.isalpha(), str3.isdigit(), str3.isalnum()))
print('"python3" -> isalpha: {}, isdigit: {}, isalnum: {}'.format(str4.isalpha(), str4.isdigit(), str4.isalnum()))
print('"python3.7" -> isalpha: {}, isdigit: {}, isalnum: {}'.format(str5.isalpha(), str5.isdigit(), str5.isalnum()))





Comments

Popular posts from this blog

making menubar and menu on QML

let's start QML programming with PySide2

QSizePolicy Fixed example in pyside2