在Python中一次测试多个标志的不同方法

2020-06-08  本文已影响0人  psh_11
# Different ways to test multiple
# flags at once in Python
# 在Python中一次测试多个标志的不同方法
x, y, z = 0, 1, 0

if x == 1 or y == 1 or z == 1:
    print('passed')

if 1 in (x, y, z):
    print('passed')

# These only test for truthiness:
if x or y or z:
    print('passed')

# any函数
if any((x, y, z)):
    print('passed')
运行结果
上一篇 下一篇

猜你喜欢

热点阅读