English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Python Functions

Python Data Types

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Python string isalnum() usage and example

Python string methods

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() parameters

isalnum() does not accept any parameters.

isalnum() return value

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

Example1:isalnum() working

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

Example1:isalnum() working

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:

Python string methods