Python编程语言中的isalnum()函数检查给定字符串中的所有字符是否都是字母数字。
字母数字:一个字母或数字的字符
用法:
string_name.isalnum()
string_name is the name of the string
参数:isalnum()方法不带参数
返回:
True: If all the characters are alphanumeric
False: If one or more characters are not alphanumeric
以下是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
相关用法
注:本文由纯净天空筛选整理自Striver大神的英文原创作品 Python string | isalnum()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。