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.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
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 asscores[0]. - A two-dimensional array (list of lists) holds grid data:
board = [[0, 0], [0, 0]], accessed asboard[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
- Identify the structural components of programs (constants, variables, initialisation, assignment, sequence, selection, repetition, iteration, data structures, subprograms, parameters, input/output) and write programs that use sequencing, selection, repetition (count-controlled, condition-controlled) and iteration with single entry and exit points.
A focused answer to Edexcel GCSE Computer Science 6.2, covering the structural components of programs and writing Python programs that use sequence, selection, count-controlled and condition-controlled repetition, and iteration.
- Write programs that manipulate strings (length, position, substrings, case conversion).
A focused answer to Edexcel GCSE Computer Science 6.3.3, covering string manipulation in Python: finding length, accessing characters by position, extracting substrings, and converting case.
- Use decomposition and abstraction to solve problems; read, write, analyse and refine programs; convert algorithms (flowcharts, pseudocode) into programs; use techniques (layout, indentation, comments, meaningful identifiers, white space) for readable code; identify, locate and correct logic, syntax and runtime errors; and evaluate a program's fitness for purpose and efficiency.
A focused answer to Edexcel GCSE Computer Science 6.1, covering using decomposition and abstraction in programs, converting algorithms to code, writing readable code, identifying and correcting errors, and evaluating fitness for purpose.
- Write programs that accept and respond appropriately to user input, and that read from and write to comma separated value text files.
A focused answer to Edexcel GCSE Computer Science 6.4.1 and 6.4.2, covering accepting and responding to user input, and reading from and writing to comma separated value (CSV) text files in Python.
- Write programs that use pre-existing and user-devised subprograms (procedures, functions), write functions that return values and procedures that do not, with or without parameters, use the arithmetic, relational and logical operators, and use global and local variables appropriately.
A focused answer to Edexcel GCSE Computer Science 6.5 and 6.6, covering functions and procedures, parameters and return values, built-in and user-defined subprograms, the operators, and global versus local variables in Python.
Sources & how we know this
- Pearson Edexcel GCSE (9-1) Computer Science (1CP2) specification — Pearson (2020)
- Pearson Edexcel GCSE Computer Science Programming Language Subset (Python) — Pearson (2020)