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


Python string isalnum()用法及代碼示例

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