.str字符串类型(二)
1. isalpha 判断目标字符串中是否只含字母
表达式 str.isalpha() ==> bool
示例:
1 a = 'alex' 2 v = a.isalpha() 3 print(v)# 输出# True
源码:

1 def isalpha(self, *args, **kwargs): # real signature unknown 2 """ 3 Return True if the string is an alphabetic string, False otherwise. 4 5 A string is alphabetic if all characters in the string are alphabetic and there 6 is at least one character in the string. 7 """
2. isdecimal
isdigit 都是用来判断目标字符串是否是数字,下面这个不光能判断纯文本,还能判断复杂符号。
表达式 str.isdecimal() ==> bool
str.isdigit() ==> bool
示例:
1 a = '②' 2 b = a.isdecimal() 3 c = a.isdigit() 4 print(b,c)# 输出# false true
源码:

1 def isdecimal(self, *args, **kwargs): # real signature unknown 2 """ 3 Return True if the string is a decimal string, False otherwise. 4 5 A string is a decimal string if all characters in the string are decimal and 6 there is at least one character in the string. 7 """

1 def isdigit(self, *args, **kwargs): # real signature unknown 2 """ 3 Return True if the string is a digit string, False otherwise. 4 5 A string is a digit string if all characters in the string are digits and there 6 is at least one character in the string. 7 """
3.