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 Generators
Jackson – Marshall String to JsonNode
Python String split()
Python List sort()
How to get current date and time in Python?
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Print Hello world!
Python Program to Safely Create a Nested Directory
Python pow()
Python Numbers, Type Conversion and Mathematics
Python Program to Check Whether a String is Palindrome or Not
Python Program to Create Pyramid Patterns
Python datetime
Python Set union()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Statement, Indentation and Comments
Python String rstrip()
Python Exception Handling Using try, except and finally statement
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python open()
Python enumerate()
Python Closures
Python compile()
Python delattr()
Python List
Converting a Stack Trace to a String in Java
Intelligent Projects Using Python - Santanu Pattanayak
Python Program to Capitalize the First Character of a String
Python min()
Python Set issuperset()
Convert String to int or Integer in Java
Python Machine Learning Eqution Reference - Sebastian Raschka