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 Program to Count the Number of Occurrence of a Character in String
JavaScript Methods of RegExp and String
Node.js vs Python for Backend Development
Python Program to Sort a Dictionary by Value
Java Program to Permute All Letters of an Input String
Python Operator Overloading
Python while Loop
Python Program to Check Whether a String is Palindrome or Not
Python bin()
Map to String Conversion in Java
Python Program to Display Fibonacci Sequence Using Recursion
Python set()
Python Program to Slice Lists
Python strptime()
Python help()
Python String rsplit()
Reading an HTTP Response Body as a String in Java
Python Program to Find the Largest Among Three Numbers
Python String isprintable()
Python sorted()
Python Directory and Files Management
Python String zfill()
Python sum()
Python String islower()
Python String lower()
Python Program to Check the File Size
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python String splitlines()
Python Program to Get the Class Name of an Instance
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
How to Get Started With Python?
Python String upper()