By Lenin Mishra
If you prefer to watch Youtube videos over reading blogs, check out our video on Python strings here.
isalnum() method in Python checks if all characters in the string are alphanumeric.
Alphanumeric characters - Alphabet letters (a-z) and numbers (0-9)
string.isalnum() Returns True or False
s1 = "Pylenin1992" print(s1.isalnum())
Example 2 - Check for a sentence
s1 = "Pylenin was born in 1992" print(s1.isalnum())
Example 3 - Check for special characters
s1 = "email@example.com" print(s1.isalnum())
As you can see,
@ is not an alphanumeric character.
Let’s check for random characters.
s1 = "!#%&?" print(s1.isalnum())
Check out other commonly used Python string methods.
- How to create a string in Python?
- How to access characters in a Python string?
- How to replace characters in a string in Python?
- How to concatenate strings in Python?
- How to iterate through a string in Python?
- Check if a Substring is Present in a Given String in Python
- Escape sequences in Python String
- Python String Formatting - The Definitive Guide