📜  Python字符串| isalnum

📅  最后修改于: 2020-07-07 05:54:18             🧑  作者: Mango

Python编程语言中的isalnum()函数检查给定字符串中的所有字符是否都是字母数字。

字母数字一个字母或数字的字符

句法:

string_name.isalnum()
string_name是字符串的名称

 

参数: isalnum()方法不带参数

返回:

True:如果所有字符都是字母数字
False:如果一个或多个字符不是字母数字

下面是isalnum()方法的Python实现

# Python program to demonstrate the use of 
# isalnum() method   
  
# here a,b and c are characters and 1,2 and 3 
# are numbers 
string = "abc123"
print(string.isalnum()) 
  
# here a,b and c are characters and 1,2 and 3  
# are numbers but space is not a alphanumeric  
# character 
string = "abc 123" 
print(string.isalnum()) 

输出:

True
False