a if condition else b
a = 2
b = 5
val = a if a > b else b
print(val) # 5
简单条件语句
if 条件:
val = 1
else:
val = 2
改成三元运算:
val = 1 if 条件成立 else 2
原文地址:https://www.cnblogs.com/liuxgcn/p/11219700.html
时间: 2024-10-10 23:38:58
a if condition else b
a = 2
b = 5
val = a if a > b else b
print(val) # 5
简单条件语句
if 条件:
val = 1
else:
val = 2
改成三元运算:
val = 1 if 条件成立 else 2
原文地址:https://www.cnblogs.com/liuxgcn/p/11219700.html