Table of Contents
The isalnum() method returns True if all characters in the string are alphanumeric (either alphabets or numbers). If not, it returns False.
The syntax of isalnum()
is:
string.isalnum()
1. isalnum() Parameters
The isalnum()
doesn’t take any parameters.
2. Return Value from isalnum()
The isalnum()
returns:
- True if all characters in the string are alphanumeric
- False if at least one character is not alphanumeric
3. Example 1: Working of isalnum()
name = "M234onica" print(name.isalnum()) # contains whitespace name = "M3onica Gell22er " print(name.isalnum()) name = "Mo3nicaGell22er" print(name.isalnum()) name = "133" print(name.isalnum())
Output
True False True True
4. Example 2: Working of isalnum()
name = "M0n1caG3ll3r" if name.isalnum() == True: print("All characters of string (name) are alphanumeric.") else: print("All characters are not alphanumeric.")
Output
All characters of string (name) are alphanumeric.
Checkout these related String methods as well:
- Python isalpha()
- Python isdigit()
Related posts:
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Get Current time
Python String rstrip()
Python Program to Find the Factorial of a Number
Convert String to int or Integer in Java
How to Get Started With Python?
Python list()
Python String format()
Python bin()
Python time Module
Python Program to Convert Decimal to Binary Using Recursion
Python String format_map()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python while Loop
Python ord()
Python Program to Print Colored Text to the Terminal
Python *args and **kwargs
Python Set union()
Python String islower()
Python Program to Catch Multiple Exceptions in One Line
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python String isdigit()
Python Shallow Copy and Deep Copy
Python String replace()
Python Program to Check the File Size
Python Program to Find the Largest Among Three Numbers
Python repr()
Python Program to Convert Two Lists Into a Dictionary
Python Anonymous / Lambda Function
Python range()
Python List sort()
Check if a String is a Palindrome in Java