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:
String Hashing
String Set Queries
Python Anonymous / Lambda Function
Python Program to Print Hello world!
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python int()
Python Program to Convert Decimal to Binary Using Recursion
Python Recursion
Python hex()
Python while Loop
Python Program to Differentiate Between type() and isinstance()
Python map()
Python String maketrans()
Python String isupper()
Python Program to Sort a Dictionary by Value
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python String translate()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Program to Get the Last Element of the List
Python time Module
Case-Insensitive String Matching in Java
Python Program to Find Factorial of Number Using Recursion
Python Program to Count the Number of Digits Present In a Number
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program to Remove Punctuations From a String
Python delattr()
Python Program to Measure the Elapsed Time in Python
Python String encode()
Python Program to Trim Whitespace From a String
Python dict()
Python Dictionary update()
Python Global, Local and Nonlocal variables