Chapter 2: Shortcut assignment statements

Swapping the values of two variables

face Josiah Wang

Let us warm up your brain with something simple first. 🔥🧠

Now, if you recall - back in Lesson 2 we talked about variable assignments.

Assignment statements

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

Swapping  values of two variables

How would you do this?

Try this, and make sure that the value of x is 24 and y is 15 in the end.