[Python] 在没有三相运算符的 Python 世界,如何优雅的去实现?


两种方法

>>> True and 1 or 0
1
>>> False and 1 or 0
0
>>> 1 if True else 0
1
>>> 1 if False else 0
0