Python Tutorial Python Advanced Python References Python Libraries

Python String - isalnum() Method



The Python isalnum() method is used to check whether all characters of the string are alphanumeric or not. It returns true when all characters of the string is alphanumeric, else returns false. Alphanumeric characters belongs to numbers 0 - 9, letters A - Z (both uppercase and lowercase).

Syntax

string.isalnum()

Parameters

No parameter is required.

Return Value

Returns True if all characters of the specified string are alphanumeric, else returns False.

Example:

In the example below, isalnum() method is used to check whether all characters of the string are alphanumeric or not.

MyString = "Hello World!"
print(MyString.isalnum())

MyString = "HelloWorld"
print(MyString.isalnum())

The output of the above code will be:

False
True

❮ Python String Methods

5