PyTricks

# Different ways to test multiple flags at once in python
x, y, z = 0, 1, 2


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


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


if any((x, y, z)):
    print('passed')
if any((x == 1, y, z > 1)):
    print('passed')
阅读更多
想对作者说点什么?