0
,而試圖消除字符串列表弦數,我試圖用類似於一個簡單的代碼:Python字符串(含空格)匹配
>>> s = ['a b', 'c d', 'e f', 'g h']
>>> for i in s:
... if i is not 'e f':
... print(i)
...
a b
c d
e f # this should not get printed, right?
g h
,我無法瞭解底層的行爲? 你能解釋一下嗎?因爲以下看起來合乎邏輯並且上面也應該相應地起作用
>>> if 'a b' is not 'a b':
... True
... else:
... False
...
False
>>> s = ['a', 'c', 'e', 'g']
>>> for i in s:
... if i is not 'e':
... print(i)
...
a
c
g
是需要特別處理的空間嗎?我錯過了什麼?