Choose exam board for KS4 Computer Science (GCSE)
Choose exam board for KS4 English
Choose exam board for KS4 French
Choose exam board for KS4 Geography
Choose exam board for KS4 German
Choose exam board for KS4 History
Choose tier for KS4 Maths
Choose exam board for KS4 Music
Choose exam board for KS4 Physical education (GCSE)
Choose exam board for KS4 Religious education (GCSE)
Choose exam board for KS4 Spanish

      Lesson details

      Learning outcome

      I can create a program using string handling techniques.

      Key learning points

      1. The contents of a string can be validated.
      2. The random module can be used to generate random numbers and pick random letters from a string.
      3. Concatenation is a way of joining strings using the + operator to make a new string.
      4. Strings can be manipulated using the upper() and lower() string methods to convert the string into upper- or lowercase.

      Keywords

      • Random - a module that can generate random numbers, pick random items or shuffle a list

      • Concatenation - the process of joining strings together to create a new string

      • Lower() - a string method that converts all letters in a string to lowercase

      • Upper() - a string method that converts all letters in a string to uppercase

      Common misconception

      The random module will only generate random numbers.

      The random module can generate random characters as well as numbers.

      Teacher tip

      For pupils who struggle to understand the strucure of strings, printing out individual letters and forming and slicing words on a table as an unplugged exercise may help visualise the process better.

      Equipment

      Pupils will need access to a device that can edit and run Python programs. Examples in this lesson use the RPF Code Editor https://oak.link/python-editor

      Licence

      This content is © Oak National Academy Limited (2026), licensed on Open Government Licence version 3.0
      except where otherwise stated. See Oak's terms & conditions
      (Collection 2).

      Lesson video

      Loading...

      Prior knowledge starter quiz

      6 Questions

      Q1.
      What is a substring?

      a function that counts characters in a string
      a variable used in loops
      Correct answer: a part of a string extracted using slicing
      a way to reverse a string

      Q2.
      What will the following Python code output?
      123
      word = "asparagus" first_three = word[0:3] print("sp" in first_three)
      Code colour

      Correct answer: True
      False
      "sp"
      Error

      Q3.
      What is ASCII?

      a programming language
      a way to store images
      Correct answer: a character encoding system that assigns numbers to characters
      a type of loop used in Python

      Q4.
      What does the following code do?
      12
      char = "G" print(ord(char))
      Code colour

      prints "G"
      Correct answer: prints the ASCII value of "G"
      prints an error message
      coverts "G" to lowecase

      Q5.
      Which Python function converts an ASCII value back into a character?

      Correct Answer: chr(), chr

      Q6.
      What does the following Python program do?
      12
      char = input("Enter a character: ") print(chr(ord(char) + 1))
      Code colour

      converts a character to uppercase
      Correct answer: shifts the character forward by one in the ASCII table
      checks if the character is a vowel
      prints the character’s length

      6 Questions

      Q1.
      What is the correct way to join the strings "blue" and "berry" into one word?

      "blue" & "berry"
      Correct answer: `"blue" + "berry"`
      "blueberry".join()
      "blueberry".concat()

      Q2.
      What must you include in your program to use the random library?

      include random
      Correct answer: import random
      using random
      from random

      Q3.
      String is joining two or more strings together.

      Correct Answer: concatenation

      Q4.
      What will be printed by the following code?
      12
      word = "Pinecone" print(word.upper())
      Code colour

      pinecone
      Correct answer: PINECONE
      PineCone
      Pinecone

      Q5.
      Which of the following correctly selects a random letter from the word "elephant"?

      random.pick("elephant")
      random.shuffle("elephant")
      Correct answer: `random.choice("elephant")`
      random.letter("elephant")

      Q6.
      The random module generates ...

      just random numbers
      just random letters
      Correct answer: any random character

      To help you plan your 10 computer science lesson on: String manipulation, download all teaching resources for free and adapt to suit your pupils' needs...