a if 条件 else b
在 return 中使用
def com(a,b): # 返回最大值 return a if a > b else b
赋值时使用:
l = 1 if 2 > 1 else 2