Challenge: Swap the Values of Two Variables

Test your understanding by solving the challenge given in this lesson.

Problem statement

Write a code to swap the values of the two variables. We have already initialized the variables var1 and var2 at the backend. Your task is to use variables var1 and var2 and swap their values.

Sample input

var1 = 1
var2 = 2

Sample output

var1 = 2
var2 = 1

Coding exercise

Before diving directly into the solution, try to solve it yourself., Then check if your code passes all the test cases. If you get stuck, you can always see the given solution.

Good luck! 👍

Get hands-on with 1400+ tech skills courses.