[python] 三元运算操作

一、三元运算符
三元运算符就是在赋值变量的时候,可以直接加判断,然后赋值
格式:result = [on_true] if [expression] else [on_false]
 res = 值1 if 条件 else 值2
1.举例说明:
a =1
b = 2
c= a if a>1 else b #如果a大于1的话,c=a,否则c=b

posted @ 2019-05-08 21:36  Moke丶青  阅读(118)  评论(0编辑  收藏  举报