Swapping Two Variables

A code to swap two variables given by the user.

Welcome to the code! Here’s a simple code to swap two variables for all the beginners to start with python programming. Swapping two variables in Python is very easy when compared to other programming languages out there. But, we can also swap two variables using a temporary variable just like the way we do in other programming languages.

In this code, the user is asked for two variables and those variables can be swapped through the below Python programming code.

Note: Loved the post? You too can publish your article on “Python for fun” which will be loved by millions. Contribute an article!

					x = input ("Enter the value of x: ")
y = input("Enter the value of y: ")

x,y = y,x

print("x =", x)
print("y =", y)				
0 0 votes
Notify of
Inline Feedbacks
View all comments