gpt4 book ai didi

python - 关于Python3中identity和boolean的一个问题

转载 作者:太空宇宙 更新时间:2023-11-03 14:36:07 25 4
gpt4 key购买 nike

我有一个关于 python 中身份的问题,我是 python 的初学者,我已经阅读了一些关于“is”关键字和“is not”的类(class)。而且我不明白为什么在 python 中操作“False is not True is not True is not False is not True”等于 False?对我而言,此操作必须返回 True。

最佳答案

python chains comparisons :

Formally, if a, b, c, …, y, z are expressions and op1, op2, …, opN are comparison operators, then a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once.

你的表达是:

False is not True is not True is not False is not True

变成:

(False is not True) and (True is not True) and (True is not False) and (False is not True)

相当于:

(True) and (False) and (True) and (True)

为假

关于python - 关于Python3中identity和boolean的一个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58308021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com