Python 3 reference · String Methods
Python String isalnum() Method
Return True if every character is a letter or a digit and the string isn't empty.
Python 3 Since 3.0
Syntax
str.isalnum()
Return value
True or False.
Examples
for s in ["abc123", "abc 123", "", "Ünïcode9"]:
print(repr(s), s.isalnum())
Output
'abc123' True 'abc 123' False '' False 'Ünïcode9' True
username = "ada_l"
print(username.replace("_", "").isalnum())
Output
True
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
str.isalpha()· Return True if every character is a letter (in any alphabet) and the string isn't empty. Spaces and digits return False.str.isdigit()· Return True if every character is a digit, including superscripts like ². Signs, spaces and decimal points return False.str.isidentifier()· Return True if the string is a valid Python identifier: a name you could use for a variable, function or class.- Python Strings · tutorial