Variables and Data Types
Variables name stored values of types like integer, float, string and boolean.
About this topic
A variable is a named place in memory that stores a value which can change while a program runs. Each value has a data type, such as integer (whole numbers), float (decimals), string (text) and boolean (true or false). The type decides what operations are allowed and how much memory is used.
Assigning a value uses the equals sign, for example score = 10, which means store 10 in score, not that they are equal in the mathematical sense. You can later write score = score + 1 to increase it. Some languages, like Python, work out types automatically (dynamic typing), while others, like Java, require you to declare them.
Choosing good names such as player_score instead of x makes code easier to read. Mixing types causes errors or surprises: adding the number 5 and the string 5 may give an error or the text 55 depending on the language. A common misconception is that a variable is a box that remembers its history; it only holds the current value. Remember that integer division and rounding of floats can lose precision.
Key ideas
- Assign with =
- Types affect what you can do
- Constants don't change
Quick check
Use cases: where Variables and Data Types helps
- Homework: review the key idea behind Variables and Data Types before you start a problem set.
- Exam revision: use the quick check to test whether you can recall Variables and Data Types without notes.
- Visual learning: play with the interactive lab to see how Variables and Data Types changes when you adjust its inputs.
- Teaching a friend: explain Variables and Data Types in your own words, then compare your version with the key ideas.
Computing ideas run phones, search engines, games and the wider internet.
Frequently asked questions
What is Variables and Data Types?
Variables name stored values of types like integer, float, string and boolean.
What will I learn in Variables and Data Types?
Assign with =. Types affect what you can do. Constants don't change.
Is Variables and Data Types part of Computer Science?
Yes. It is one of 80 Computer Science topics on LearnViz HighSchoolEdu, with 3 key ideas, a live animation and a quick check.
Does the Variables and Data Types lab work on a phone or tablet?
Yes. The animation resizes to fit your screen and supports touch, so you can drag, tap and slide with your finger.
How should I study Variables and Data Types?
Read the summary and key ideas first, play with the interactive lab to see the idea in motion, then answer the quick check. If you get a question wrong, go back to the key idea it tests.
Do I need an account, and is my progress saved?
No account is needed. Marking a topic as learned is saved in your own browser, so it stays on that device and is not sent to a server.