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:
Convert Character Array to String in Java
Python Program to Randomly Select an Element From the List
Python Dictionary popitem()
Python Program to Extract Extension From the File Name
Java – String to Reader
Python Program to Find the Factors of a Number
Python Program to Get Line Count of a File
Python strptime()
Python Program to Convert Two Lists Into a Dictionary
Python Program to Check Prime Number
Python Program to Check Whether a String is Palindrome or Not
Count Occurrences of a Char in a String
Python Program to Find Hash of File
Python Program to Display the multiplication Table
Python Program to Print Hello world!
Python Program to Catch Multiple Exceptions in One Line
Python while Loop
Python Program to Count the Number of Occurrence of a Character in String
Format ZonedDateTime to String
Python Dictionary copy()
Python sum()
Python Program to Display Fibonacci Sequence Using Recursion
Python Program to Convert Decimal to Binary Using Recursion
Python time Module
Converting a List to String in Java
Python Set clear()
Python Set issuperset()
Python Program to Count the Number of Each Vowel
Python String zfill()
APIs in Node.js vs Python - A Comparison
Python datetime
CharSequence vs. String in Java