在 python 中比较 2 个错误陈述的正确方法是什么?
What is the correct way to compare 2 false statements in python?
给定示例代码:
if not token == '-' or token == '+':
print token
检测到 - 但未检测到 +
如果我将代码编辑为:
if not token == '-' or not token == '+':
print token
均未检测到。
最简单的方法:
if token not in '-+':
但传统上,将 not
放在某些或...
之外
if not (token == '-' or token == '+'):
给定示例代码:
if not token == '-' or token == '+':
print token
检测到 - 但未检测到 +
如果我将代码编辑为:
if not token == '-' or not token == '+':
print token
均未检测到。
最简单的方法:
if token not in '-+':
但传统上,将 not
放在某些或...
if not (token == '-' or token == '+'):