(Turn) python to determine whether the string is a number or letter

Original address https://www.cnblogs.com/wangboqi/p/7455240.html 

Strict analysis: symbols other than numbers or letters (spaces, semicolons, etc.) will be False

isalnum() must be numbers and letters Mixed
isalpha() is case insensitive
str_1 = "123"
str_2 = "Abc"
str_3 = "123Abc"

#Use the isdigit function to determine whether a number 
print (str_1.isdigit())
Ture
print(str_2.isdigit())
False
print(str_3.isdigit())
False

#Use isalpha to determine whether the letter 
print (str_1.isalpha())    
False
print(str_2.isalpha())
Ture    
print(str_3.isalpha())    
False

# isalnum determines whether the combination of numbers and letters 
print (str_1.isalpha())    
False
print(str_2.isalpha())
False
print(str_1.isalpha())    
Ture

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324608923&siteId=291194637