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 Generators
Python complex()
Java InputStream to String
Python String count()
Python ascii()
Python Custom Exceptions
Python filter()
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Set add()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Operators
Python Program to Get File Creation and Modification Date
Python File I/O Operation
Python Data Structures and Algorithms - Benjamin Baka
Python Program to Access Index of a List Using for Loop
Python Set update()
Python Program to Compute all the Permutation of the String
Most commonly used String methods in Java
Python List index()
Python sleep()
Python Set difference_update()
Python String format()
Converting a List to String in Java
Python Program to Display Powers of 2 Using Anonymous Function
Python bool()
Reading an HTTP Response Body as a String in Java
Python Modules
Python vars()
Python String strip()
Python Program to Generate a Random Number
Python Program to Make a Simple Calculator
Python for Loop