isalnum() method of str class

isalnum() method of str class returns True if every character in the string is a letter or a digit and the string has at least one character; otherwise it returns False.

Str Updated 24 Nov 2026 1 min read

Method Name

isalnum

Method Signature

isalnum()

Method Overview

  • The isalnum() method of str class in Python, returns True if the string contains only alphabets and/or digits.

  • isalnum() returns False if the string has at least one non-alphanumeric character or no alphanumeric character.

Return Value

  • True - if all the characters in the string are letters or digits and the string is not empty.

  • False - if the string contains at least one character that is not a letter or a digit (for example, a space or a symbol), or if the string is empty.

How Python's str.isalnum() checks each character

Each character must be a letter or a digit, and the string must not be empty, for isalnum() to return True.

Example

python
testString  = "Year1969"

status      = testString.isalnum()

print("Given string is Alphanumeric:{}".format(status))

numString  = "123987"

status      = numString.isalnum()

print("Given string is Alphanumeric:{}".format(status))

spString    = "*% @#$"

status      = spString.isalnum()

print("Given string is Alphanumeric:{}".format(status))

Output

Output
Given string is Alphanumeric:True

Given string is Alphanumeric:True

Given string is Alphanumeric:False