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 input()
Python staticmethod()
Python Program to Display Calendar
Python hex()
Python dict()
Why String is Immutable in Java?
Python Statement, Indentation and Comments
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Convert Kilometers to Miles
Python List
Python Program to Concatenate Two Lists
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Type Conversion and Type Casting
Convert char to String in Java
Python Deep Learning Cookbook - Indra den Bakker
Python Global Keyword
Python Program to Shuffle Deck of Cards
Python String isupper()
Python Program to Check If a String Is a Number (Float)
Python Program to Find ASCII Value of Character
Python issubclass()
Python Program to Parse a String to a Float or Int
Java – Reader to String
Python Program to Get the Last Element of the List
Python setattr()
Python getattr()
Java String to InputStream
Python String istitle()
Python sum()
Python String isdecimal()
Introduction to Scientific Programming with Python - Joakim Sundnes
Most commonly used String methods in Java