Home >>Python Programs >Python program to swap the values of two variables
In this example, we will see how we can swap two numbers in the Python language. Swapping two variables means the mutual exchange of values of the variables. It is generally done by using a temporary variable.
Example :
# Python swap program
x = input('Enter value of x: ')
y = input('Enter value of y: ')
# create a temporary variable and swap the values
temp = x
x = y
y = temp
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))