一、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
S1 = '12345' #純數字
S2 = '①②' #帶圈的數字
S3 = '漢字' #漢字
S4 = '%#¥' #特殊符號
print(S1.isdigit())
print(S2.isdigit())
print(S3.isdigit())
print(S4.isdigit())
# 執行結果:
True
True
False
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
'''
遇到問題沒人解答?小編創建了一個Python學習交流QQ羣:579817333
尋找有志同道合的小夥伴,互幫互助,羣裏還有不錯的視頻學習教程和PDF電子書!
'''
S1 = 'abc漢字' #漢字+字母
S2 = 'ab字134' #包含數字
S3 = '*&&' #特殊符號
print(S1.isalpha())
print(S2.isalpha())
print(S3.isalpha())
#執行結果
True
False
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
'''
遇到問題沒人解答?小編創建了一個Python學習交流QQ羣:579817333
尋找有志同道合的小夥伴,互幫互助,羣裏還有不錯的視頻學習教程和PDF電子書!
'''
S1 = 'abc漢字1' #字母+漢字+數字
S2 = '①②③' #帶圈的數字
S3 = '%……&' #特殊符號
print(S1.isalnum())
print(S2.isalnum())
print(S3.isalnum())
#執行結果
True
True
False
注意點:
1.python官方定義中的字母:大家默認爲英文字母+漢字即可
2.python官方定義中的數字:大家默認爲阿拉伯數字+帶圈的數字即可
相信只要理解到這兩點,這三個函數的在使用時的具體返回值,大家就很明確了~~