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
是需要特别处理的空间吗?我错过了什么?