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:
Count Occurrences of a Char in a String
Python Set intersection()
Converting a List to String in Java
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python ord()
Python help()
Python Program to Print Colored Text to the Terminal
Python Program to Sort a Dictionary by Value
Python Program to Check Prime Number
Jackson – Marshall String to JsonNode
Format ZonedDateTime to String
Python Program to Sort Words in Alphabetic Order
Python Dictionary get()
Converting String to Stream of chars
Python Dictionary setdefault()
Python Program to Check If a List is Empty
Python sum()
Python bin()
Python Statement, Indentation and Comments
Python set()
Python complex()
Python map()
Python Program to Remove Punctuations From a String
Python Program to Solve Quadratic Equation
Python String find()
Python Dictionary values()
Python Program to Represent enum
Python Directory and Files Management
Python Program to Get the Last Element of the List
Python String isalpha()
Python Program to Print all Prime Numbers in an Interval