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 strptime()
Python Program to Check the File Size
Python sum()
Python Program to Display Fibonacci Sequence Using Recursion
JavaScript Eval: run a code string
Python for Loop
Python List append()
Python Directory and Files Management
Python Program to Convert Two Lists Into a Dictionary
Python String isidentifier()
Python Data Structures and Algorithms - Benjamin Baka
Python Tuple index()
Python Program to Find Numbers Divisible by Another Number
Python format()
Python String isupper()
Python Program to Remove Punctuations From a String
Python Program to Find All File with .txt Extension Present Inside a Directory
Python open()
Python Program to Count the Number of Digits Present In a Number
Python bytearray()
Python issubclass()
Python Dictionary popitem()
Python Dictionary get()
Python Program to Find LCM
Python any()
Python Program to Find the Factorial of a Number
Python float()
String Hashing
Python Dictionary items()
How to Get Started With Python?
Python File I/O Operation
Python List remove()