Fork me on GitHub

python 三目运算符

格式: true_res if condition else false_res

Meto 1:

Meto 2:

>>> x = 2

>>> x+1 if x!=1 else --x

3

 

posted @ 2019-01-02 10:06  路痴队长  阅读(159)  评论(0)    收藏  举报