Variables
Turn to Page 394. In this lesson we delve into the concept of data containers – variables.
˙⋆˖⁺‧₊☽◯☾₊‧⁺˖⋆˙
Definition
Variables are fundamental in programming as they allow us to store and manipulate data.
Variable
Variable Naming Rules
When naming variables, there are certain rules to follow:
- • A variable name must start with a letter or an underscore (_), followed by letters, digits, or underscores.
- • Variable names are case-sensitive, meaning uppercase and lowercase letters are treated differently.
- • Variable names cannot be reserved keywords in Python, such as
print ,if ,else , etc.
Variable Assignment
To assign a value to a variable, we use the assignment operator (
Variables can be of different types.
Variable Reassignment
Once a variable is assigned a value, you can change its value by assigning a new value to it. This process is known as variable reassignment.
Practical Application
You are tasked with brewing a potion and need to store the ingredients and their quantities in variables. Create variables for the following:
Unicorn Hair: 3 strands
Phoenix Feather: 1 feather