Variables - Lakelands Computing

Title
Go to content
Variables
In programming a variable is a place where you can store a single piece of data, for example a name, an age or a score.

In some languages you need to create the variable (make it), set it's data type and then store the data in in. In others (Python being one) you can do all three of these steps in one go.

A variable is actually a small part of RAM that is reserved to store a single piece of data. The variable name serves as a "user friendly version" of the address of that reserved part of RAM.
In the Scratch example the variable has been called score. It is increased by 1 when the sprite is clicked

In the Python example there are 2 variables : score which is set to 0 and then set to 1, and q which is set to the answer of the question (this example also includes an if statement and a comparisson == checks to see if they are equal)
All Text copyright Lakelands Academy & Mr T Purslow 2020.
All images copyright free / creative commons unless otherwise stated.
You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
Back to content