Menu Close

Python String isalnum() Method

Python string isalnum() method

In this article, you will learn about the Python string isalnum() method. Python isalnum() method is used to work with string.
String isalnum function in python is a built-in string function which used to check a string contains alphanumeric characters or not.


In the previous tutorial, we have seen the string isalpha() method to check string contains alphabets or not.

Python String isalnum() Method

The isalnum() method is used to return True if all the characters of the string are alphanumeric otherwise return False.
A character that is either later or number is known as alphanumeric. It does not allow
special characters even species.

Syntax:

The syntax of the string isalnum() method is:-

string.isalnum()

Parameter:

String isalnum() method not support any parameter.

Return Type:

Python string isalnum function in python returns Boolean value: True or False

Python String isalnum() Method Example:

Here we will take various examples to understand string isalnum method.

Example 1:

str = "Programming"
str2 = str.isalnum()
print(str2)

Output will be:- True

In above example, Output will be True because str contain alphabets.

Example 2:

str = "123456789"
str2 = str.isalnum()
print(str2)

Output will be:- True

In above example, Output will be True because str contain numerics.

Example 3:

str = "Programming12"
str2 = str.isalnum()
print(str2)

Output will be:- True

In above example, Output will be True because str contain alphabets as well as numeric.

Note:- Python string isalnum() method return True, if the staring contains either alphabets or numeric or both.

Example 4:

str = "Programming  23"
str2 = str.isalnum()
print(str2)

Output will be:- False

In the above example, Output will be False because str contains alphabets, numeric as well as spaces, and as you know that string isalnum function in python does not allow spaces.

Conclusion:

In this tutorial, you have learned the Python string isalnum() method to check whether a string is alphanumeric or not.
if the string alphanumeric, Then the string isalnum function in python will return True otherwise return False.

I hope this tutorial will help you, if you like this article, please share with your friends who want to learn Python programming from scratch to advanced.

For More Information:- Click Here

Previous Article
Next Article

Was this post helpful?

Related Posts

Leave a Reply