New
New
Year 10
OCR

Substrings

I can slice a string to create a substring and then use list methods on the substring.

New
New
Year 10
OCR

Substrings

I can slice a string to create a substring and then use list methods on the substring.

These resources will be removed by end of Summer Term 2025.

Switch to our new teaching resources now - designed by teachers and leading subject experts, and tested in classrooms.

These resources were created for remote use during the pandemic and are not designed for classroom teaching.

Lesson details

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.


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

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.
Teacher tip

Equipment

All pupils requires access to devices that can edit and run Python programs. Starter code files are available to copy or use directly via the Raspberry Pi Code Editor.

Licence

This content is © Oak National Academy Limited (2025), 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

Download quiz pdf

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

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords

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

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords

h
Correct answer: o
l
IndexError

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

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords

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"

Assessment exit quiz

Download quiz pdf

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

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords

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

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords

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