Variables & data types (concept)
Computer Science · Programming fundamentals
Question 1 of 10
0What is the type of True in Python?
Stuck? Read the explanation
Unlocks at a streak of 5 correct answers in a row.
Embed this practice on your site or class page
Paste this HTML into your page. Students practise right there; it is free and needs no account.
Variables & data types (concept) explained
Variables are named containers that hold values while a program runs. A data type tells the computer what kind of value a variable holds and which operations make sense for it. The common types are integer (whole numbers), real or float (numbers with a decimal part), string (text) and boolean (true or false).
When a value is assigned to a variable, the variable can usually be changed later. The type matters because it changes how the same symbol behaves. Adding two integers gives an integer, but adding two strings joins them together.
Type names differ between courses. GCSE pseudocode often uses INTEGER, REAL, CHAR, STRING and BOOLEAN, Python uses int, float, str and bool, and Java uses int and double. Some languages, such as Python, work out the type from the value you assign, while others, such as Java, need you to declare it.
A common mistake is to think that "5" and 5 are the same. In quotation marks, 5 is text, so "5" + "3" gives "53", while 5 + 3 gives 8.
Worked example
A shop sells a notebook for $4.50 and a customer buys 3. Store the price as a real number, the quantity as an integer, and work out the total:
price = 4.50
quantity = 3
total = price * quantity
The calculation is , so total holds the real number 13.5. Multiplying a real number by an integer gives a real number.
What you will practise
104 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.
Example questions
- A variable is:
- An integer is:
- A string is:
- A boolean can hold:
- Type mismatch errors occur when:
- A float (floating-point number) is a data type used to store:
- The data type of a variable determines:
- In most languages, the assignment operator = means:
…and 96 more.