Discuss / Python / 关于Python的 and 运算符问题

关于Python的 and 运算符问题

请问Python的and运算符的运算顺序是先计算第一个参数,若为false则返回第一个参数;若为true则返回第二个参数吗?

有代码如下:

print None and 'C'
#output: None
print 'abc' and 'bcd'
#output: bcd
print 'abc' and None
#output: None

请指教,谢谢

Confidendure

#2 Created at ... [Delete] [Delete and Lock User]

True and 'whatever‘ 返回右边的值 False and 'whatever' 返回左边的值 True or 'whatever' 返回左边的值 False or 'whatever' 返回右边的值

记得0、None都被视为False,其他视为True


  • 1

Reply