一、链式赋值
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
二、交叉赋值
'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:857662006
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
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
网友评论