Skip to main content
EnglandComputer ScienceSyllabus dot point

What are the primitive and structured data types, and how do you use variables and constants in Python?

Write programs that make appropriate use of primitive data types (integer, real, Boolean, char) and one- and two-dimensional structured data types (string, array, record), and that make appropriate use of variables and constants.

A focused answer to Edexcel GCSE Computer Science 6.3.1 and 6.3.2, covering the primitive data types (integer, real, Boolean, char), structured types (string, array, record) in one and two dimensions, and using variables and constants.

Generated by Claude Opus 4.89 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. Primitive data types
  3. Structured data types
  4. Variables and constants
  5. Try this

What this dot point is asking

Edexcel wants you to choose and use the right data types: the primitive types (integer, real, Boolean, char) and the structured types (string, array, record) in one and two dimensions, and to use variables and constants appropriately in Python.

Primitive data types

Choosing the correct type matters for both correctness and efficiency. An integer suits a count or an age in whole years; a real suits money or a measurement with decimals; a Boolean suits a yes/no flag such as "is logged in"; a char suits a single character such as a grade. A common exam task gives several items and asks for the best type with a reason (for example "real, because a price has pounds and pence").

Structured data types

The structures suit different shapes of data:

  • A string holds text: name = "Sam".
  • A one-dimensional array (list) holds a list of similar items: scores = [10, 8, 9, 7], accessed as scores[0].
  • A two-dimensional array (list of lists) holds grid data: board = [[0, 0], [0, 0]], accessed as board[row][col].
  • A record groups related, possibly mixed-type values: a student's name (string), age (integer) and average (real) together.
scores = [10, 8, 9, 7]        # 1D array (list)
print(scores[2])              # accesses 9 (index from 0)

grid = [[1, 2, 3],
        [4, 5, 6]]            # 2D array (list of lists)
print(grid[1][0])             # accesses 4 (row 1, column 0)

Variables and constants

Using a constant for a fixed value (a tax rate, a maximum number of players) makes code clearer and safer: the name documents the value, and changing it means editing one line. Using variables for changing values keeps the program flexible. Choosing variable versus constant correctly, and naming both meaningfully, is part of writing readable code.

Try this

Q1. State the most appropriate data type for storing whether a light is on or off. [1 mark]

  • Cue. Boolean (True or False).

Q2. State one reason to use a two-dimensional array rather than many separate variables. [1 mark]

  • Cue. It stores grid data under one name, accessed by two indices and processed with loops.

Exam-style practice questions

Practice questions written in the style of Pearson Edexcel exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

Edexcel 20224 marksState the most appropriate data type (integer, real, Boolean or string) for each of the following, giving a reason for one of them: (a) a person's age in whole years, (b) a price in pounds and pence, (c) whether a user is logged in, (d) a postcode.
Show worked answer →

(a) Integer, because an age in whole years is a whole number. (b) Real (float), because a price has a fractional part (pounds and pence). (c) Boolean, because logged in is either true or false. (d) String, because a postcode contains letters and digits and is treated as text, not used in calculations.

A reason, for example for (b): a real (float) is needed because money has decimal places, which an integer could not store.

Markers reward the four correct types and a valid reason for at least one (whole number versus decimal, true/false, or text not used in arithmetic).

Edexcel 20214 marksA program needs to store the scores of 4 players for each of 3 rounds. Explain why a two-dimensional array is suitable, and write a Python line that creates such a structure initialised to 0.
Show worked answer →

A two-dimensional array (a list of lists in Python) is suitable because the data is a grid of rows and columns (players by rounds), so it can be stored under one name and accessed by two indices (player and round), and processed with nested loops, rather than needing many separate variables.

A line creating a 4 by 3 structure of zeros:

scores = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]

Markers reward explaining that a 2D array suits grid data accessed by two indices and processed with loops, and a correct Python structure (a list of lists) of the right shape initialised to 0.

Related dot points

Sources & how we know this