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)

  

posted on 2018-04-28 11:04  PAYNE1Z  阅读(105)  评论(0编辑  收藏  举报