Home > Backend Development > Python Tutorial > How does Python determine that the input is all letters?

How does Python determine that the input is all letters?

silencement
Release: 2019-06-17 13:21:49
Original
10233 people have browsed it

How does Python determine that the input is all letters?

Strict analysis: any symbols other than numbers or letters (spaces, semicolons, etc.) will be False
isalnum() must be a mixture of numbers and letters
isalpha() is not case-sensitive

str_1 = "123"
str_2 = "Abc"
str_3 = "123Abc"

#用isdigit函数判断是否数字
print(str_1.isdigit())
Ture
print(str_2.isdigit())
False
print(str_3.isdigit())
False

#用isalpha判断是否字母
print(str_1.isalpha())    
False
print(str_2.isalpha())
Ture    
print(str_3.isalpha())    
False

#isalnum判断是否数字和字母的组合
print(str_1.isalnum())    
Ture
print(str_2.isalnum())
Ture
print(str_1.isalnum())    
Ture
Copy after login

Note: If the string contains characters other than letters or numbers, such as spaces, it will also return False

The above is the detailed content of How does Python determine that the input is all letters?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template