Exercise_8
Exercise 8 : Branch and Leap 1
Test :
if not (money < 100) : if money >= 100
assert condition(False) #AssertionError
交换 a=1, b=2,c=3
a,b,c = c,a,b
(x < y and [x] or [y])[0]
实现三元操作符功能 x if condition else y
成员资格运算符 : in 如果在序列中返回True,否则False
Try :
将以下代码使用三元操作符实现
1
2
3
4
5
6
7
8
9
10
11x, y, z = 6, 5, 4
if x < y:
small = x
if z < small:
small = z
elif y < z:
small = y
else:
small = z
可以改成:
small = x if(x < y and x < z) else (y if y< z else z)
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!