How Can We Help?
In this tutorial, we will explain how to use Python string isalnum() method with basic syntax by example for better understanding.
The String isalnum() method returns True if all the characters of the string are alphanumeric; otherwise, it returns False.
Syntax:
<string_value/string_variable>.isalnum()
Input Parameters:
- string_value / String variable : The string that we want to check whether it’s alphanumeric or not.
Python String is alphanumeric
We can check the string value it’s alphanumeric or not by simply using the isalnum() method. It means the string value contains both characters and numbers. one example of an alphanumeric value is “abcd1234” and a non-alphanumeric value is “@ ^$#%()!” means spaces or special characters.
Example (1)
# The String Value That We Want To Check whether it's alphanumeric or not.
msg='welcome to python'
print ('String variable is an alphanumeric:',msg.isalnum())
Output of example (1)
String variable is an alphanumeric: False
In the above example, the string variable ‘msg’ includes alphabets with spaces. When we checked the alphanumeric data type of it by msg.isalnum() in a print statement, it shows False.
Example (2)
#Print String After fill zero at the end of the string value
print('String is an alphanumeric:','python36'.isalnum())
Output of example (2)
String is an alphanumeric: True
In the above example, the string value ‘python36’ includes an alphabet with numeric values, so when we checked the alphanumeric data type of it by ‘python36’.isalnum() in a print statement, then it shows the result as True.
In this tutorial, you have learned the string isalnum() method in Python. What is it? And how to check whether the string value is alphanumeric or not.
Hopefully, it was clear and concise.
If you have an inquiry or doubt, don’t hesitate to leave them in a comment. We are waiting for your valuable feedback.
Similar Python String Checking Methods:
- isdigit() : It returns True if all the characters of the string are digit; otherwise, it returns False.
- isnumeric() : It returns True if all the characters of the string are numeric; otherwise, it returns False.
- isdecimal() : It returns True if all the characters of the string are decimal; otherwise, it returns False.
- isalpha() : It returns True if all the string characters are the alphabet; otherwise, it returns False.
- islower() : It returns True if all the string characters are in lowercase; otherwise, it returns False.
- isupper() : It returns False if all the string characters are in an uppercase; otherwise, it returns False.
- isspace() : It returns True if all the characters of a string are whitespace; otherwise, it returns False.
- istitle() : It returns True if all the string words are properly “title cased”; otherwise, it returns False.
- startswith() : It returns True if the string starts with a given substring between the given start and end index; otherwise, it returns False.
- endswith() : It returns True if the string ends with a given substring between start and end index; otherwise, it returns False.
Related Articles
Python String – Mastering By Practical Examples (Comprehensive Guide)
Python Tutorials List:
- Python tutorials list : access all python tutorials.