是否有更优雅的pythonic方式表达以下condional表达式?

cur*_*ous 6 python

如果有的话,我想为下面的分支更加pythonic方式:

if a<b:
   a.append('value')
elif a==b:
   b.append('value')
else:
   do nothing
Run Code Online (Sandbox Code Playgroud)

那有三元运算符吗?

Vol*_*ity 4

使用嵌套三元运算符。

func1() if a<b else func2() if a==b else func3()
Run Code Online (Sandbox Code Playgroud)

对于您的具体示例:

a.append('value') if a<b else b.append('value') if a==b else None
Run Code Online (Sandbox Code Playgroud)

  • 现在你让我有了打高尔夫球的心情 `[func2,func3,func1][cmp(a,b)]()` (7认同)