在测试会员资格时,我们可以使用:
x not in y
Run Code Online (Sandbox Code Playgroud)
或者:
not y in x
Run Code Online (Sandbox Code Playgroud)
根据x和,这个表达式可能有许多可能的上下文y.例如,它可以用于子字符串检查,列表成员资格,字典密钥存在.
这里的答案提供了一个手工引用的参考,你想要__ne__返回的东西不仅仅是逻辑逆__eq__,但我无法想象任何这样的情况.任何例子?
test = ''
# This loop infinitely
while test != 'O' or test != 'X':
test = raw_input("Enter: ").upper()
# This works fine
while not(test == 'O' or test == 'X'):
test = raw_input("Enter: ").upper()
Run Code Online (Sandbox Code Playgroud)
推杆not和使用之间有什么区别!=?