python基础-04花式赋值
链式赋值
上列子:
a = 10
b = 10
c = 10
d = 10
print(f'a:{a}, b:{b}, c:{c}, d:{d}')
# 结果---> a:10, b:10, c:10, d:10
a = b = c = d = 10
print(f'a:{a}, b:{b}, c:{c}, d:{d}')
# 结果---> a:10, b:10, c:10, d:10
交叉赋值
x = 100
y = 200
temp = x
x = y
y = temp
print(f'x:{x}')
print(f'y:{y}')
# 结果如 ----->x:200 y:100
x, y = y, x
print(f'x:{x}')
print(f'y:{y}')
#结果如 ----->x:100 y:200
解压赋值
见链接 -->