
Fountain Studios
Variables
Coding Concept
Variables are used as placeholders for pieces of text (strings), numerical values, commands, and even other variables. A variable inside a piece of code is replaced by a number or text when the code is run. You can think of a variable as a box that contains something (a number or text). Set and Call
Command Structure
Here we can see that the command is made up of two parts. The first part sets the variable_name to a value and the second part calls the variable in the code by writing its name variable_name.
variable_name = value
Syntax and Rules
Use underscores and no spaces when naming a variable.
You can not use just one number as a variable name but can use a combination of letters and numbers.
a variable's value can be a string, number, or another variable.
Examples
Below are some examples of variables:
count = 1
count = count + 1
print(count)
Displays 2 on the screen
dogs_name = "Jack"
print(dogs_name)
Displays Jack on the screen
Unplugged Activity
If you wanted to make a box/variable for countries, you could name your box/variable country. You can then pass the box called country to another student who places a piece of paper with the name of a country (America) inside the box. This gives the box/variable country a value of America. The box is then moved to another student who places their country of choice (France) inside the box and removes the previous one (America). The box/variable now has the value (France). Any time you want to see the current country, you can open the box/variable country and have a look.
Coding Resources
-
Python Online Dictionary for kids
-
Minecraft Dictionary