Lesson 5
Writing Reusable and Self-explanatory Programs
Chapter 2: Shortcut assignment statements
Swapping the values of two variables
Let us warm up your brain with something simple first. 🔥ðŸ§
Now, if you recall - back in Lesson 2 we talked about variable assignments.
Now, let us say we have two variables x
, and y
:
x = 15
y = 24
We would like to swap the values of the variables. After swapping, we want x
to be pointing to what y
was pointing (24
in our example); and we want y
to be pointing to what x
was pointing (15
in this example).
How would you do this?
Try this, and make sure that the value of x
is 24
and y
is 15
in the end.