How to swap two variables value in python?
For example, If you have a equal to 1 and b equal to 2 then get output a equal to 2 and b equal to 1.
First create c variable then set c equal to a, a equal to b and b equal to c.
Here is code,
a = 1
b = 2
print("OLD a = ",a)
print("OLD b = ",b)
c = a
a = b
b = c
print("a = ",a)
print("b = ",b)
Output:
OLD a = 1
OLD b = 2
a = 2
b = 1