把一个if-elif-else语句放在一行上？

Python是否有三元条件运算符？ （这个问题是关于将if-else语句压缩到一行）

``if expression1: statement1 elif expression2: statement2 else: statement3` `

[UPDATE]

` `if i>100: x=2 elif i<100: x=1 else: x=0` `

` `x=2 if i>100 elif i<100 1 else 0 [WRONG]` `

` `>>> a = "Hello" if foo() else "Goodbye"` `

` `>>> 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` `

` `expr1 if condition1 else expr2 if condition2 else expr` `

` `a = "neg" if b<0 else "pos" if b>0 else "zero"` `

` `>>> x=5 >>> x if x>0 else ("zero" if x==0 else "invalid value") 5 >>> x = 0 >>> x if x>0 else ("zero" if x==0 else "invalid value") 'zero' >>> x = -1 >>> x if x>0 else ("zero" if x==0 else "invalid value") 'invalid value'` `

` `def save(): ... def edit(): ... options = {"save": save, "edit": edit, "remove": lambda : "Not Implemented"} option = get_input() result = options[option]()` `

（而不是

` `if option=="save": save() ...` `

` `x = (i>100 and 2) or (i<100 and 1) or 0` `

` `x = {i>100: 2, i<100: 1}.get(True, 0)` `

` `x = 2*(i>100) | 1*(i<100)` `