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 del Statement
Python iter()
Python Decorators
APIs in Node.js vs Python - A Comparison
Python range()
Python String ljust()
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Illustrate Different Set Operations
Python Program to Get the Last Element of the List
Java InputStream to String
Python issubclass()
Python list()
Python Variables, Constants and Literals
Python Operator Overloading
Count Occurrences of a Char in a String
Python setattr()
Python open()
Encode a String to UTF-8 in Java
Python List
Jackson – Marshall String to JsonNode
Python List insert()
Python String rstrip()
Python property()
Python String partition()
Python Dictionary update()
Python String isalpha()
Python int()
Deep Learning in Python - LazyProgrammer
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Set remove()
Python Global Keyword
Check if a String is a Palindrome in Java