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:
Convert Character Array to String in Java
Python Set intersection()
Python dict()
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python slice()
Split a String in Java
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python any()
Python Set update()
Python sleep()
Java – Reader to String
Python String find()
Python print()
Python Program to Find Sum of Natural Numbers Using Recursion
Python Objects and Classes
Python Program to Compute the Power of a Number
Python Program to Check if a Key is Already Present in a Dictionary
Python pass statement
Python Get Current time
Python hash()
Convert String to Byte Array and Reverse in Java
Python List clear()
Python String join()
Convert String to int or Integer in Java
Python zip()
Python Dictionary values()
Python Program to Slice Lists
Python String isnumeric()
Intelligent Projects Using Python - Santanu Pattanayak
Python Program to Get File Creation and Modification Date
Python Dictionary fromkeys()