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 slice a string to create a substring and then use list methods on the substring.

      Key learning points

      1. A substring is a part of a string.
      2. Slicing can be used to separate a string into substrings.
      3. ASCII is a character set used to represent all of the characters on a standard American or English keyboard.

      Keywords

      • Substring - part of a string

      • Slice - the process of extracting a specific substring

      • ASCII - a character set that represents each character with a unique numerical value

      Common misconception

      Indexing starts at 1 as that is the location of the first element.

      In Python, and many other programming languages, indexing starts at 0.

      Teacher tip

      This lessons uses iteration to access each item in a string. Pupils may need to revisit the concept of iteration if they are not confident with the concept.

      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 string in programming?

      a type of loop used for iteration
      Correct answer: a sequence of characters, including letters, numbers and symbols
      a function that counts elements in a list
      a data type used only for numbers

      Q2.
      How do you determine the length of a string in Python?

      count(string)
      size(string)
      length(string)
      Correct answer: `len(string)`

      Q3.
      What will this program output?
      12
      word = "Python" print(word[3])
      Code colour

      Correct Answer: h

      Q4.
      What will happen if you try to access an index that is greater than or equal to the string length?

      The program will return an empty string.
      The program will print "Error".
      Correct answer: The program will crash with an "IndexError".
      The program will ignore the request.

      Q5.
      What does the following code print?
      12
      word = "hello" print(word[-1])
      Code colour

      h
      Correct answer: o
      l
      IndexError

      Q6.
      What does the following code output?
      123
      word = "hello" for letter in word: print(letter)
      Code colour

      h e l l o (on one line)
      hello (as a single word)
      Correct answer: each letter printed on a new line
      the number of letters in "hello"

      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?
      12
      word = "HELLO" print(word[1:4])
      Code colour

      HEL
      HELL
      Correct answer: ELL
      LLO

      Q3.
      What is the correct syntax to extract the substring "pin" from "pineapple", which is stored in the variable fruit?

      Correct answer: `fruit[0:3]`
      fruit[1:4]
      fruit[3:6]
      fruit[4:9]

      Q4.
      Which of the following statements about slicing in Python is true?

      The stop index in slicing is included in the substring.
      Correct answer: The stop index in slicing is excluded from the substring.
      The start index must always be 0.
      Slicing does not work with numbers in a string.

      Q5.
      How do you check if the substring "apple" is in the string "pineapple"?

      "apple" == "pineapple"
      Correct answer: `"apple" in "pineapple"`
      "pineapple" in "apple"
      contains("pineapple", "apple")

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

      prints the character entered
      Correct answer: prints the ASCII value of the entered character
      converts a character to lowercase
      checks if the character is a vowel

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