True
,则布尔运算符 'and' 返回
True
。 0 以外的任何数字都是 True。所以 python 应该返回
True
for
13 and 19
但是为什么它返回19?Agan,python 应该返回 True
13 and 9
但是为什么 python 返回 9?
如果双方字面上都是and
,则布尔运算符返回True
True
True
,则情况就是这样,正如毫不奇怪地,
True and True
是
True
。对于其他值,它们是否真实,在这种情况下,链中的最后一个值是传播的值。这是因为您并不总是需要布尔值。如果它返回一个布尔值并“吃掉”你的字符串,
test = x and "works!" or "nope"
会很烦人。