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 Program to Count the Number of Digits Present In a Number
Python String partition()
Python String rsplit()
Split a String in Java
Reading an HTTP Response Body as a String in Java
Python range()
Python Program to Print Hello world!
Python vars()
Python Program to Convert Decimal to Binary Using Recursion
Python String splitlines()
Python Set intersection_update()
Python Program to Find LCM
Python Program to Find Numbers Divisible by Another Number
Converting a List to String in Java
Python Program to Shuffle Deck of Cards
Converting a Stack Trace to a String in Java
Python Program to Transpose a Matrix
Python repr()
Python Closures
Python Program to Add Two Matrices
Python Program to Merge Two Dictionaries
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Convert Character Array to String in Java
Python String startswith()
Python min()
Python String isdigit()
Python RegEx
Python divmod()
Python Program to Print Output Without a Newline
Java String to InputStream
Python int()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants