PartsOfBody Asked:2024-04-18 02:26:01 +0800 CST2024-04-18 02:26:01 +0800 CST 2024-04-18 02:26:01 +0800 CST 在python中比较值 772 尽管该条件等于 ,但它不起作用True。最初的代码相当广泛。屏幕截图显示了其中的一部分以及工作值。 有必要比较两个变量stop_loss_new和stop_loss_old。类型和值显示在调试器窗口中。还给出了比较变量的结果,如您所见True。然而,在该条件中,if逻辑表达式不会返回True,因为“检查点”不再显示。也许这是由于变量的类型所致,那么不清楚为什么上面打印 True。 python 1 个回答 Voted Best Answer PaveTranquil 2024-04-18T02:32:50+08:002024-04-18T02:32:50+08:00 if statement == True- 永远不要这样写;)首先,它相当于if statement. 其次,可能会出现操作优先级的问题。在你的情况下,(stop_loss_new > stop_loss_old) == True它会返回True,但stop_loss_new > stop_loss_old == True它会返回False。 你只需要写: if stop_loss_new > stop_loss_old。
if statement == True
- 永远不要这样写;)首先,它相当于if statement
. 其次,可能会出现操作优先级的问题。在你的情况下,(stop_loss_new > stop_loss_old) == True
它会返回True
,但stop_loss_new > stop_loss_old == True
它会返回False
。你只需要写:
if stop_loss_new > stop_loss_old
。