📜  python if elif else in one line - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:23.353000             🧑  作者: Mango

代码示例1
>>> i=100
>>> a = 1 if i<100 else 2 if i>100 else 0
>>> a
0
>>> i=101
>>> a = 1 if i<100 else 2 if i>100 else 0
>>> a
2
>>> i=99
>>> a = 1 if i<100 else 2 if i>100 else 0
>>> a
1