首页 > 其他 > 详细

三无操作的应用

时间:2018-04-28 11:31:32      阅读:175      评论:0      收藏:0      [点我收藏+]
 a, b, c = 1, 3, 5
print(a, b, c)

d = a if a > b else c # 三元操作符:如果 a>b 则 d=a 否则 d=c
print(d)

d = a if a < b else c # 三元操作符:如果 a<b 则 d=a 否则 d=c
print(d)

# 用三元操作符找出较小的那个
x, y = 3987, 24361
small = (x if x < y else y)
print(small)

# 比较三个数的大小,找出较小的那个
x, y, z = 8, 9, 1
small = (x if x < y else y)
small = (small if small < z else z)
print(small)

x, y, z = 8, 4, 11
small = ((x if x < y else y) if (x if x < y else y) < z else z)
print(small)

x, y, z = 8, 20, 1
if x < y:
    small = x
else:
    small = y

if small < z:
    print(small)
else:
    print(z)

  

三无操作的应用

原文:https://www.cnblogs.com/PAYNE1Z/p/8966463.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!