In this section, we will learn what String isalnum() method is and how to use it in Python.
What is String isalnum() Method in Python?
The Python string isalnum() method is used to check a string value to see if the letters in it are just alphabet characters (a-z) and/or numeric (0-9).
Python String isalnum() Method Syntax:
String isalnum() Method Parameter
The method does not take an argument.
String isalnum() Method Return Value
The return value of this method is of boolean type.
The value True will return if the target string value only contains alphabet characters and/or numbers.
But if the target string has any non alphanumeric character (Like: [email protected]#$%^&*()_+- (white-space), then the return value of this method becomes False.
Example: using python string isalnum() method
s1= "THIS IS A SENTENCE" s2 = "Hello" s3 = "@# 122" print(s1.isalnum()) print(s2.isalnum()) print(s3.isalnum())
False True False
For the string value of the `s1` variable, we can see that there are white spaces between some characters of the string value. For this reason, the result of calling the `isalnum()` method returned the value False.