当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python String isalnum()用法及代码示例

Python String isalnum() 方法检查给定字符串中的所有字符是否都是字母数字。字母数字表示字母或数字的字符。

Syntax: 

string_name.isalnum() 

参数: 

isalnum() method takes no parameters 



Return: 

  • True: If all the characters are alphanumeric 
  • False: If one or more characters are not alphanumeric 

例 1: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() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。