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 Anonymous / Lambda Function
String Processing with Apache Commons Lang 3
Python List index()
Python type()
Python List sort()
Python File I/O Operation
Python Dictionary clear()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Program to Reverse a Number
Python open()
Python Set copy()
Python reversed()
Python Program to Check Prime Number
Python String find()
Python List copy()
Python Set intersection_update()
Python Dictionary pop()
Python bytes()
Python Dictionary items()
JavaScript Methods of RegExp and String
Python Objects and Classes
Python List reverse()
Python Program to Count the Occurrence of an Item in a List
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Convert Character Array to String in Java
Python delattr()
Python Closures
Check if a String is a Palindrome in Java
Python chr()
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python String rindex()