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 Get a Substring of a String
Python Program to Compute the Power of a Number
Python Program to Find the Size (Resolution) of a Image
Python Program to Access Index of a List Using for Loop
Python Program to Find Sum of Natural Numbers Using Recursion
Python time Module
Python Tuple index()
Python Program to Create a Long Multiline String
Python Program to Count the Occurrence of an Item in a List
Python Program to Get the Last Element of the List
Python oct()
Count Occurrences of a Char in a String
Python all()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Get the Class Name of an Instance
Python abs()
Python Data Structures and Algorithms - Benjamin Baka
Python Program to Print the Fibonacci sequence
Python datetime
Python Program to Iterate Through Two Lists in Parallel
Python Program to Convert Kilometers to Miles
Python Program to Make a Simple Calculator
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python zip()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Set pop()
Python Program to Check Leap Year
Python Program to Print Hello world!
Format ZonedDateTime to String
Python next()
Python isinstance()
Python Program to Create a Countdown Timer