Python String isalnum() method
Python String isalnum() method
The string.isalnum () method in Python returns a boolean value true if all characters in the string are alphanumeric else for any other value it returns false.
Syntax
String.isalnum()
Parameter
NA
Return
This method returns a Boolean value True if all the given characters are alphanumeric.
Example 1
# Python programing explaining # the isalnum() method # initializing a alhanumeric value without validating any space strVal = "July2019"; print (strVal.isalnum()) # passing string value strVal = "Hello World !!"; print (strVal.isalnum())
Output
True False
Example 2
# Python programing explaining # the isalnum() method # initializing a string value strVal = "M0n1caG3ll3r" # validating if and else condition if strVal.isalnum() == True: print("All characters of specified string are alphanumeric.") else: print("All the characters are not alphanumeric.")
Output
All characters of specified string are alphanumeric.
Example 3
# Python programing explaining # the isalnum() method # initializing a string value # will return true char1 = "M234onica" print(char1.isalnum()) # contains whitespace # will return False as it contains space char2 = "M3onica Gell22er " print(char2.isalnum()) #passing special characters # will return false as it contains special characters char3 = "!Mo3nica*$Gell22er" print(char3.isalnum()) # passing all integers # will return true as it is alphanumeric char4 = "133" print(char4.isalnum())
Output
True False False True