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

Python basic tutorial

Python flow control

Fonctions en Python

Types de données en Python

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Usage and examples of Python string isalnum()

String methods in Python

If all characters in the string are alphanumeric (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: the work of isalnum()

name = "M234onica"
print(name.isalnum())
# Contains spaces
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: the work of isalnum()

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:

String methods in Python