swap to variables python code example
Example 1: python swap numbers
x, y = 10, 20
print(x, y) # 10 20
x, y = y, x
print(x, y) # 20 10
Example 2: swapping in python
x = 5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)
x, y = 10, 20
print(x, y) # 10 20
x, y = y, x
print(x, y) # 20 10
x = 5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)