花式赋值


Python从入门到放弃完整教程目录:https://www.cnblogs.com/nickchen121/p/10718112.html

一、链式赋值

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
posted @ 2019-06-22 18:57  B站-水论文的程序猿  阅读(3482)  评论(0编辑  收藏  举报