how swap numbers in 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: code to swap in python
a=5
b=10
a,b=b,a #swapped
x, y = 10, 20
print(x, y) # 10 20
x, y = y, x
print(x, y) # 20 10
a=5
b=10
a,b=b,a #swapped