Programming

Python for GCSE Computer Science — Complete Beginner's Guide

Learn Python from scratch for GCSE Computer Science. Variables, loops, functions, lists, file handling and more — with clear examples and exam-style questions covered.

Gareth Edgell

Gareth Edgell

Head of CS · Senior Examiner · 15+ years tutoring

PythonGCSEprogrammingbeginnercoding

Python is the most widely-used programming language in GCSE Computer Science teaching. Whether you’re an absolute beginner or brushing up before your exam, this guide covers all the Python concepts you need — with real examples you can try yourself.

Why Python for GCSE?

Python has a clean, readable syntax that makes it ideal for learning programming. Unlike some languages, Python reads almost like English — which helps you focus on thinking like a programmer rather than wrestling with complex syntax.

At GCSE level, you’ll use Python to:

  • Solve problems using sequences, selection, and iteration
  • Handle string input and output
  • Work with lists and files
  • Write functions
  • Demonstrate your understanding of algorithms

1. Variables and Data Types

A variable is a named storage location that holds a value. In Python, you don’t need to declare a type — Python works it out automatically.

name = "Alice"         # string (text)
age = 16               # integer (whole number)
height = 1.72          # float (decimal number)
is_student = True      # boolean (True or False)

Casting between types

# Convert string to integer
age_text = "16"
age = int(age_text)

# Convert integer to string
score = 95
message = "Your score is " + str(score)

# Get input (always returns a string)
name = input("Enter your name: ")
age = int(input("Enter your age: "))  # cast immediately

2. Output

print("Hello, world!")
print("Name:", name)
print(f"Hello, {name}! You are {age} years old.")  # f-strings (Python 3.6+)

Note: AQA pseudocode uses OUTPUT, OCR uses print(). The concept is identical.


3. Arithmetic Operators

OperatorMeaningExampleResult
+Addition5 + 38
-Subtraction10 - 46
*Multiplication3 * 412
/Division (float)7 / 23.5
//Integer division7 // 23
%Modulo (remainder)7 % 21
**Exponentiation2 ** 38

The modulo operator (%) is very useful in GCSE questions — it’s commonly used to check if a number is even (x % 2 == 0).


4. Selection (if/elif/else)

grade = int(input("Enter your grade: "))

if grade >= 70:
    print("Distinction")
elif grade >= 50:
    print("Merit")
elif grade >= 40:
    print("Pass")
else:
    print("Fail")

Comparison operators

  • == equal to
  • != not equal to
  • > greater than
  • < less than
  • >= greater than or equal to
  • <= less than or equal to

Logical operators

if age >= 16 and age < 18:
    print("You are a sixth-former")

if subject == "CS" or subject == "IT":
    print("Tech subject")

if not is_finished:
    print("Keep working")

5. Iteration (Loops)

For loops — repeat a known number of times

# Count from 0 to 4
for i in range(5):
    print(i)

# Count from 1 to 10
for i in range(1, 11):
    print(i)

# Loop through a list
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)

While loops — repeat while a condition is true

# Countdown
count = 10
while count > 0:
    print(count)
    count -= 1
print("Blast off!")

# Input validation loop
age = int(input("Enter age: "))
while age < 0 or age > 120:
    print("Invalid age. Try again.")
    age = int(input("Enter age: "))

Examiner tip: Input validation using a while loop is one of the most tested patterns at GCSE. Learn it by heart.


6. String Operations

name = "Computer Science"

# Length
print(len(name))          # 16

# Upper and lower case
print(name.upper())       # COMPUTER SCIENCE
print(name.lower())       # computer science

# Substrings (slicing)
print(name[0])            # C  (first character)
print(name[0:8])          # Computer
print(name[-7:])          # Science  (from the end)

# Concatenation
first = "Gareth"
last = "Edgell"
full = first + " " + last

# Finding and replacing
print(name.find("Science"))     # returns index where it starts
print(name.replace("Science", "Studies"))

# Check if substring is present
if "Computer" in name:
    print("Found it!")

7. Lists

Lists store multiple values in order. They are called arrays in most GCSE specs (the concept is the same).

# Creating a list
scores = [85, 72, 91, 68, 79]

# Accessing elements (index starts at 0)
print(scores[0])     # 85 (first element)
print(scores[-1])    # 79 (last element)

# Modifying elements
scores[2] = 95

# Length
print(len(scores))   # 5

# Adding and removing
scores.append(88)    # add to end
scores.remove(72)    # remove first occurrence of 72

# Looping through a list
for score in scores:
    print(score)

# 2D list (like a table/grid)
grid = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]
print(grid[1][2])    # 6 (row 1, column 2)

8. Functions (Subprograms)

Functions let you write code once and reuse it. They are called subprograms or procedures/functions in GCSE specs.

# A procedure (no return value)
def greet(name):
    print(f"Hello, {name}!")

greet("Alice")
greet("Bob")

# A function (returns a value)
def calculate_area(length, width):
    area = length * width
    return area

result = calculate_area(5, 3)
print(result)    # 15

# Function with a default parameter
def power(base, exponent=2):
    return base ** exponent

print(power(4))      # 16 (uses default exponent of 2)
print(power(2, 3))   # 8

9. File Handling

# Writing to a file
file = open("scores.txt", "w")   # "w" = write (overwrites existing)
file.write("Alice,85\n")
file.write("Bob,72\n")
file.close()

# Appending to a file
file = open("scores.txt", "a")   # "a" = append
file.write("Carol,91\n")
file.close()

# Reading from a file
file = open("scores.txt", "r")   # "r" = read
content = file.read()            # read entire file
file.close()
print(content)

# Reading line by line
file = open("scores.txt", "r")
for line in file:
    print(line.strip())          # strip() removes the newline character
file.close()

10. Common GCSE Exam Patterns

These patterns come up repeatedly in GCSE exam questions:

Finding the largest value in a list

scores = [85, 72, 91, 68, 79]
largest = scores[0]
for score in scores:
    if score > largest:
        largest = score
print("Largest:", largest)

Counting occurrences

grades = ["A", "B", "A", "C", "A", "B"]
count = 0
for grade in grades:
    if grade == "A":
        count += 1
print("Number of As:", count)
def linear_search(lst, target):
    for i in range(len(lst)):
        if lst[i] == target:
            return i   # return the index
    return -1          # not found

names = ["Alice", "Bob", "Carol", "Dave"]
result = linear_search(names, "Carol")
print(result)    # 2

Bubble sort

def bubble_sort(lst):
    n = len(lst)
    for pass_num in range(n - 1):
        for i in range(n - 1 - pass_num):
            if lst[i] > lst[i + 1]:
                lst[i], lst[i + 1] = lst[i + 1], lst[i]
    return lst

numbers = [64, 34, 25, 12, 22, 11]
print(bubble_sort(numbers))

Practice Tips

  1. Type the code yourself — don’t just read it. Muscle memory matters for programming.
  2. Predict then test — before running code, predict what it will output.
  3. Break problems down — start with pseudocode, then translate to Python.
  4. Use the IDLE interpreter — test small snippets immediately.
  5. Read error messages — they tell you exactly what went wrong and on which line.

Our Python course on the revision platform walks you through everything above with interactive exercises, from beginner through to A Level standard.

Need personalised help with Python? Book a 1-to-1 session and we’ll work through your specific problem areas together.

Gareth Edgell

Want personalised help?

Book a 1-to-1 session with Gareth — your spec, your pace, your gaps fixed.