swap values of variables in python code example
Example 1: code to swap in python
a=5
b=10
a,b=b,a #swapped
Example 2: swapping variables in python
a = 1
b = 2
a, b = b, a
# a = 2 , b = 1
a=5
b=10
a,b=b,a #swapped
a = 1
b = 2
a, b = b, a
# a = 2 , b = 1