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 String format()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Operators
Python Program to Display Calendar
Python exec()
Python Program to Extract Extension From the File Name
Python while Loop
Python Closures
Python Generators
Python Program to Find HCF or GCD
Java InputStream to String
Python map()
Python Program to Find Numbers Divisible by Another Number
Python globals()
String Hashing
Python Dictionary update()
Python print()
Python String rindex()
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Convert String to Datetime
Python frozenset()
Python Set pop()
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Safely Create a Nested Directory
Python Errors and Built-in Exceptions
Python pass statement
Most commonly used String methods in Java
Python List Comprehension
Python Program to Transpose a Matrix
Python Program to Split a List Into Evenly Sized Chunks
Reading an HTTP Response Body as a String in Java
Python eval()