Skip to main content

isalnum()

The isalnum() method in Python is a string method that returns True if all characters in the string are alphanumeric (either letters or numbers), and there is at least one character. Otherwise, it returns False.

Parameter Values

This function does not accept any parameters.

Return Values

The isalnum() method returns a bool value: True or False.

How to Use isalnum() in Python

Example 1:

The isalnum() method returns True if all characters in the string are alphanumeric (either alphabets or numbers), otherwise it returns False.

x = 'abc123'
print(x.isalnum())
Example 2:

The isalnum() method also considers empty strings as non-alphanumeric, so it will return False for empty strings.

y = ''
print(y.isalnum())
Example 3:

Using the isalnum() method on a string with special characters will return False as it checks for only alphanumeric characters.

z = 'hello@123'
print(z.isalnum())