The isalnum() method detects whether a string consists of only letters and numbers.
Example
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
# include spaces
str1 = 'Happy Brithday to you'
# include specific character
str2 = 'Walmart#'
# include letters and number
str3 = 'ABCDabcd123'
print (str1.isalnum())
print (str2.isalnum())
print (str3.isalnum())
Output:
False
False
True
Syntax
str.isalnum()
Parameters
The method doesn’t take any parameters.
Return Value
It returns True and False, depending on whether the string is alphanumeric.