Method Name
isalnum
Method Signature
isalnum()
Method Overview
The isalnum() method of str class in Python, returns True if the string contains only alphabets and/or digits.
isalnum() returns False if the string has at least one non-alphanumeric character or no alphanumeric character.
Return Value
True - if all the characters in the string are letters or digits and the string is not empty.
False - if the string contains at least one character that is not a letter or a digit (for example, a space or a symbol), or if the string is empty.
Each character must be a letter or a digit, and the string must not be empty, for isalnum() to return True.
Example
testString = "Year1969"
status = testString.isalnum()
print("Given string is Alphanumeric:{}".format(status))
numString = "123987"
status = numString.isalnum()
print("Given string is Alphanumeric:{}".format(status))
spString = "*% @#$"
status = spString.isalnum()
print("Given string is Alphanumeric:{}".format(status))Output
Given string is Alphanumeric:True
Given string is Alphanumeric:True
Given string is Alphanumeric:False