English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
If all characters in the string are letters or numbers (letters or numbers), the isalnum() method will return True. If not, it will return False.
The syntax of isalnum() is:
string.isalnum()
isalnum() does not accept any parameters.
isalnum() returns:
True If all characters in the string are letters or numbers
False If at least one character is not a letter or number
name = "M234onica" print(name.isalnum()) # Include space name = "M3onica Gell22er " print(name.isalnum()) name = "Mo3nicaGell22er" print(name.isalnum()) name = "133" print(name.isalnum())
When running the program, the output is:
True False True True
name = "M0n1caG3ll3r" if name.isalnum() == True: print("All characters of the string (name) are alphanumeric.") else: print("All characters are not alphanumeric.")
When running the program, the output is:
All characters of the string (name) are alphanumeric.
Other related String methods: