Home / Python / Reference / String methods

Python string isalnum() method

Check whether every character is a letter or a digit.

Syntax

str.isalnum()

Parameters

None.

Return value

bool

Example

Code

print("abc123".isalnum(), "abc 123".isalnum(), "abc-123".isalnum())
print("".join(ch for ch in "A man, a plan!" if ch.isalnum()))

Output

True False False
Amanaplan

Related

Learn it step by step in the free lesson Strings, with exercises that check your answers.