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 String isspace()
Python File I/O Operation
Python String strip()
Python Program to Count the Number of Each Vowel
Python Dictionary fromkeys()
Python Program to Parse a String to a Float or Int
Python Program to Measure the Elapsed Time in Python
Generate a String
Python List remove()
Python Dictionary get()
Python complex()
Python exec()
Python Set clear()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Strings
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python enumerate()
Python Modules
Python filter()
Python issubclass()
Python Program to Check If Two Strings are Anagram
Python Program to Swap Two Variables
Python Program to Make a Flattened List from Nested List
Python Set symmetric_difference_update()
Python Program to Randomly Select an Element From the List
Python Program to Solve Quadratic Equation
Python dict()
Python map()
Python Program to Reverse a Number
Converting String to Stream of chars
Python Set pop()
Python callable()