一、isdigit()
python关于 isdigit() 内置函数的官方定义:
S.isdigit() -> bool
Return True if all characters in S are digits
and there is at least one character in S, False otherwise.
翻译:
S.isdigit()返回的是布尔值:True False
S中至少有一个字符且如果S中的所有字符都是数字,那么返回结果就是True;否则,就返回False
1 S1 = '12345' #纯数字
2 S2 = '①②' #带圈的数字
3 S3 = '汉字' #汉字
4 S4 = '%#¥' #特殊符号
5
6 print(S1.isdigit())7 print(S2.isdigit())8 print(S3.isdigit())9 print(S4.isdigit())10
11 #执行结果:
12 True13 True14 False15 False
二、isalpha()
python关于 isalpha() 内置函数的官方定义:
S.isalpha() -> bool
Return True if all characters in S are alphabetic
and there is at least one character in S, False otherwise.
翻译:
S.isalpha()返回的是布尔值:True False
S中至少有一个字符且如果S中的所有字符都是字母,那么返回结果就是True;否则,就返回False
1 S1 = 'abc汉字' #汉字+字母
2 S2 = 'ab字134' #包含数字
3 S3 = '*&&' #特殊符号
4
5 print(S1.isalpha())6 print(S2.isalpha())7 print(S3.isalpha())8
9 #执行结果
10 True11 False12 False
三、isalnum()
python关于 isalnum() 内置函数的官方定义:
S.isalnum() -> bool
Return True if all characters in S are alphanumeric
and there is at least one character in S, False otherwise.
翻译:
S.isalnum()返回的是布尔值:True False
S中至少有一个字符且如果S中的所有字符都是字母数字,那么返回结果就是True;否则,就返回False
1 S1 = 'abc汉字1' #字母+汉字+数字
2 S2 = '①②③' #带圈的数字
3 S3 = '%……&' #特殊符号
4
5 print(S1.isalnum())6 print(S2.isalnum())7 print(S3.isalnum())8
9 #执行结果
10 True11 True12 False
注意点:
1.python官方定义中的字母:大家默认为英文字母+汉字即可
2.python官方定义中的数字:大家默认为阿拉伯数字+带圈的数字即可
相信只要理解到这两点,这三个函数的在使用时的具体返回值,大家就很明确了~~