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

Letters and digits onlyTry it yourself
for s in ["abc123", "abc 123", "", "Ünïcode9"]:
    print(repr(s), s.isalnum())

Output

'abc123' True
'abc 123' False
'' False
'Ünïcode9' True
Allow some extra charactersTry it yourself
username = "ada_l"
print(username.replace("_", "").isalnum())

Output

True

Version history

VersionChange
Python 3.0Added