在python中可以通過in和not in關鍵字來判讀一個list中是否包含一個元素:
str = ['s','i','m','o','n']
if 'e' in str:
print("e in str")
else:
print('e not in str')
輸出:e not in str
if 's' in str :
print('s in str')
輸出:s in str
in 和 not in 是非常常用的關鍵字。
在python中可以通過in和not in關鍵字來判讀一個list中是否包含一個元素:
str = ['s','i','m','o','n']
if 'e' in str:
print("e in str")
else:
print('e not in str')
輸出:e not in str
if 's' in str :
print('s in str')
輸出:s in str
in 和 not in 是非常常用的關鍵字。
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。