>> -6ren">
gpt4 book ai didi

Python:在 [] == False 中打印 "word"

转载 作者:太空狗 更新时间:2023-10-30 01:45:10 24 4
gpt4 key购买 nike

在这里尝试弄清楚这在 python 中的作用有点费脑:

print "word" in [] == False

为什么打印 False

最佳答案

也许下面是这种异常行为的一个更明显的例子:

>>> print 'word' in ['word']
True
>>> print 'word' in ['word'] == True
False

你的例子相当于:

print ("word" in []) and ([] == False)

这是因为可以组合两个 bool 表达式,目的是允许这种缩写:

a < x < b

对于这个更长但等效的表达式:

(a < x) and (x < b)

关于Python:在 [] == False 中打印 "word",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7616691/

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