Python Program to Swap Two Variables


Hello friends, this is a python program to swap two variables




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Python program to swap two variables
# provided by the user

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))

Output:

Enter value of x: 3
Enter value of y: 4
The value of x after swapping: 4
The value of y after swapping: 3

Comments