Python学习笔记:isalnum()函数的用法
Python学习笔记:isalnum()函数的用法
isalnum()函数:检测字符串是否由字母和数字组成,若字符串由数字和字母组成则返回true,否则返回false
str1 = 'python'
print(str1.isalnum()) # True
str2 = 'python学习'
print(str2.isalnum()) # true
str3 = '123'
print(str3.isalnum()) # true
str4 = 'Python123'
print(str4.isalnum()) # true
str5 = 'python 123'
print(str5.isalnum()) # 有空格所以返回false