Variables are a way of storing values so that we can use them again (and again) throughout our program or change them, if necessary.
Values can be a number or a piece of text.
Variables are a way of saving a piece of info with a specific name. We can reuse a value over and over again, when we give that value a name.
For example, we can pick a variable my_locker_number, and store a value into it.
That way, we can reuse that value over and over again in our code, without having to type out my_locker_number and the value, every single time.
my_locker_number = 223625
my_locker_number / 3
my_locker_number * 5
Two important reasons why we need variables in our code:
- To easily reuse values in different parts of our code – more efficient, avoid repetition, no hardcoding
- To change the values of our variables – more flexible, with multiple options (for example, drop downs)
Hardcoding: When you use a value without assigning it to a variable.
To declare a variable, we give the variable a name and set it equal to a value.
For example, name of variable: my_locker_number and value: 223625 becomes:
my_locker_number = '223625'
Video: What Makes an Effective Programmer?
… CONTINUE READING