Python string isalnum() method
Python String isalnum() Method
Description
The isalnum() method is used to check whether a string consists of alphanumeric characters.
Syntax
The syntax of the isalnum() method is as follows:
var.isalnum()
Parameters
None
Return Value
This method returns True if all characters in the string are alphanumeric. It returns False if it contains any non-alphanumeric characters (other than letters and numbers).
Example
The following example shows the usage of the isalnum() method.
var = "Explicit is better than implicit."
var1 = var.isalnum()
print ("Raw string:", var)
print ("Is it alphanumeric?:", var1)
var = "TutorialsPoint"
var2 = var.isalnum()
print ("Raw string:", var)
print ("Is it alphanumeric?:", var2)
var = "123.45"
var3 = var.isalnum()
print ("Raw string:", var)
print ("Is it alphanumeric?:", var3)
When you run this program, it will produce the following output −
Raw string: Explicit is better than implicit.
Is it alphanumeric?: False
Raw string: TutorialsPoint
Is it alphanumeric?: True
Original string: 123.45
Is it alphanumeric?: False