
isalnum() Method –
isalnum() method return True if all the characters of a string is alphanumeric (i.e. alphabets or numbers). If not then it returns False.
Syntax –
string.isalnum()
Example –
In [1]: string1 = 'abc123'
In [2]: string1.isalnum()
Out[2]: True
In [3]: string2 = 'abc 123'
In [4]: string2.isalnum()
Out[4]: False
The result of second string is False because the string also contains a white space along with numbers and alphabets.
Related Posts –
- Python String Method – Capitalize()
- Python String Method – title()
- Python String Method – center()
- Python String Method – count()
- Python String Method – startswith()
- Python String Method – endswith()
- Python String Method – find()
- Python String Method – index()