Python study notes (6): usage of isalpha() function

isalpha() method: Determine whether the string is composed of only letters. If all characters in the string are letters, it returns True, otherwise it returns False.

str1 = "python"
print(str1.isalpha()) #True

# 中文的汉字会被isalpha判定为True
str2 = "我是一只大花猫"
print(str2.isalpha()) # True
# 如果想区分中文和英文可以使用unicode,中文的范围为:['/u4e00','/u9fa5']
print(str2.encode("utf-8").isalpha()) # False

str3 = "cat花猫"
print(str3.isalpha()) # True
print(str3.encode("utf-8").isalpha()) # False

 

Guess you like

Origin blog.csdn.net/weixin_44679832/article/details/113926623