Python isalnum

Python isalnum is one of the String Methods used to check whether the given character is either an alphabet or a numeric value. In this section, we discuss how to write the Python isalnum Function with an example, and the syntax is

String_Value.isalnum()

Python isalnum function to check alphanumerics

The following set of examples helps you understand the isalnum function. Please refer to the String and Methods articles in Python to understand them easily.

First, we declared the String variable Str1 and assigned Integer Value using the following Str1 statement. Next, we used it to check whether the string is alphanumeric or not. As you can see, it is a digit, so the function returns TRUE.

For Str5, we are using the isdigit function on both digits and alphabets.

Str1 = '123456789';
print('First Output of a method is = ', Str1.isalnum())

Str2 = '     ';
print('Output of a method For Empty Space is = ', Str1.isalnum())

# Performing on Alphabets
Str3 = 'TutorialGateway'.isalnum()
print('Second Output is = ', Str3)

# Performing on both Digits and Alphabets
Str5 = '1239abcd'.isalnum()
print('Third Output is = ', Str5)

# Performing on Float values
Str6 = '1234.67'.isalnum()
print('Fourth Output is = ', Str6)

# Performing on Negative Values  
Str7 = '-1234'.isalnum()
print('Fifth Output is = ', Str7)
Python isalnum function check string is alpha numeric Example