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 Dictionary items()
Python List append()
Convert String to Byte Array and Reverse in Java
Python Program to Print Hello world!
Java InputStream to String
Python sum()
Python Dictionary values()
Python hasattr()
Python String isspace()
Python Package
Python zip()
Python String splitlines()
Python break and continue
Java Program to Permute All Letters of an Input String
Deep Learning in Python - LazyProgrammer
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Namespace and Scope
Python Exception Handling Using try, except and finally statement
Python Program to Get the File Name From the File Path
String Set Queries
Python bool()
Check If a String Is Numeric in Java
Python Program to Find All File with .txt Extension Present Inside a Directory
Python String isdecimal()
Python Program to Remove Duplicate Element From a List
Python List index()
Python Program to Sort a Dictionary by Value
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Find the Sum of Natural Numbers
Format ZonedDateTime to String
Python String format_map()
String Initialization in Java