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 Differentiate Between del, remove, and pop on a List
Python Program to Count the Number of Each Vowel
Split a String in Java
Python pass statement
Python Variables, Constants and Literals
Python String rfind()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Compute the Power of a Number
Python String find()
Python tuple()
Python @property decorator
Machine Learning with Python for everyone - Mark E.Fenner
Python getattr()
Python Program to Represent enum
Python Program to Find the Size (Resolution) of a Image
Python Set issuperset()
Python String lstrip()
Python Program to Find Sum of Natural Numbers Using Recursion
Python Data Types
Python Dictionary items()
Python Data Structures and Algorithms - Benjamin Baka
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Program to Count the Occurrence of an Item in a List
Python Set symmetric_difference()
Python List remove()
Python filter()
Python Program to Get File Creation and Modification Date
Java Program to Permute All Letters of an Input String
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Find Numbers Divisible by Another Number
Python Global, Local and Nonlocal variables
Python Program Read a File Line by Line Into a List