格式为:条件成立时的返回值 if 条件 else 条件不成立时的返回值
条件成立时的返回值 if 条件 else 条件不成立时的返回值
x = 10 y = 20 print(x if x > y else y) #使用三元表达式进行if判断并输出结果 # 20
age=int(input('请输入你的年龄: ')) res='老女人' if age >18 else '小仙女' #使用三元表达式进行if判断获取结果 print(res) # 请输入你的年龄: 18 # 小仙女