字串比對非常重要,在程式設計時,因為有很多變化即是由這個地方開始的
idstr="abcdefghijklmnopqstuvwxyz"
chk_bool ='a' in idstr
print(chk_bool)
=========
True
idstr="abcdefghijklmnopqstuvwxyz"
chk_bool ='a' not in idstr
print(chk_bool)
=========
False
idstr='abcdefghijklmnopqstuvwxyz'
chk_l = idstr.find('a')
chk_r =idstr.rfind("z")
print(chk_l)
print(chk_r)
=========
0
24
===============================
身分證檢驗
def idchar(inchr): # Use a breakpoint in the code line below to debug your script. idstr = 'abcdefghijklmnopqstuvwxyz'.upper() pos=idstr.find(inchr)+10 return pos # Press the green button in the gutter to run the script. if __name__ == '__main__': inids="A123456789" print(idchar(inids[0])) chksum=0 #中間數字 for i in range(1,len(inids)-1): chksum+=(9-i)*int(inids[i]) #最後一個數字 chksum+=int(inids[len(inids)-1]) # 第一字母 chksum += idchar(inids[0])//10 + (idchar(inids[0])%10)*9
================
idstr='abcdefghijklmnopqstuvwxyz'
chk_c = idstr.count('a')
print(chk_c)
=======
1