當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。