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:
Converting a Stack Trace to a String in Java
Check If a String Is Numeric in Java
Python Set union()
Python bin()
Python while Loop
Python Program to Count the Occurrence of an Item in a List
Python List append()
Python Program to Find Hash of File
Python String lower()
Python all()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python String isnumeric()
Python Program to Check Armstrong Number
Python Set intersection()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python Program to Check Prime Number
Python Program to Trim Whitespace From a String
Python String title()
Python Program to Get File Creation and Modification Date
Python sum()
Map to String Conversion in Java
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Multiple Inheritance
Python List count()
Python String capitalize()
Python Program to Find the Size (Resolution) of a Image
Java InputStream to String
Python locals()
Java – Generate Random String
Python String count()
Python frozenset()
Python int()