Lesson 2
The Basic Elements
Chapter 6: Variables
Variables
It will be tedious to always have 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.
As we have previously seen in our guessing game, you can assign an object to a variable with an assignment statement.
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.