Python isalnum

Python isalnum is one of the Python 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 isalnum Function in Python Programming with example. The syntax of the isalnum function is

String_Value.isalnum()
  • String_Value: Please select a valid String literal.

Program to Check for Digit, or alphabet using Python isalnum

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

# Python isalnum Method Example

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

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

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

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

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

# Performing isalnum() on Negative Values  
Str7 = '-1234'.isalnum()
print('Fifth Output of a isalnum() method is = ', Str7)
Python isalnum 1

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

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

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

Str5 = '1239abcd'.isalnum()
print('Third Output of a isalnum() method is = ', Str5)