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 Safely Create a Nested Directory
Python Deep Learning Cookbook - Indra den Bakker
Python sorted()
Python Program to Check If a String Is a Number (Float)
Python Program to Check if a Number is Positive, Negative or 0
Convert String to int or Integer in Java
Node.js vs Python for Backend Development
Python String rindex()
Python Variables, Constants and Literals
Python Dictionary get()
Python Dictionary update()
Python any()
Python Program to Convert Decimal to Binary Using Recursion
CharSequence vs. String in Java
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Get the File Name From the File Path
Python issubclass()
Python bytes()
Python vars()
Python Program to Sort a Dictionary by Value
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Errors and Built-in Exceptions
Python Program to Find the Square Root
Python String rstrip()
Case-Insensitive String Matching in Java
Python strptime()
Python Set intersection()
Python Program to Add Two Numbers
Python Data Structures and Algorithms - Benjamin Baka
Python String format()
Python zip()
Python Directory and Files Management