This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 6: Variables

Variables

face Josiah Wang

It will be tedious always having to refer to an object as 345 + 321.

It is like me having to refer to you as the person who is 168cm tall and has long and black hair, etc. every time I need to call you.

Therefore, we can assign a name or label to any object in Python.

In Python, a variable is simply a name or a label that points to an object instance in memory.

Variable is a name pointing to an object

As we have previously seen in our guessing game, you can assign an object to a variable with an assignment statement.

Assignment statements points a variable to an object

You should be familiar with the assignment operator by now: =.

Remember: This is NOT an equality operator. This is an assignment operator.

You are also not ‘solving’ for the variable as in Mathematics.

Instead, you ‘let’ the variable on the left hand side (LHS) point to the object on the right hand side (RHS). Just remember the diagram above and you will be fine.