Python 中的“not in”運算子是什麼?
在 Python 中,'not in' 成員運算子 如果在指定的序列中找不到變數,則評估為true,否則為false。例如
>>> a = 10
>>> b = 4
>>> l1 = [1,2,3,4,5]
>>> a not in l1
True
>>> b not in l1
False
由於'a' 不屬於 l1,a not in b 返回 True。但是,b 可以在 l1 中找到,因此 b not in l1 返回 False
開啟您的 職業生涯
透過完成課程獲得認證
開始學習