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 use string handling techniques to find things out about a string.

      Key learning points

      1. A string is a collection of characters.
      2. String handling is using techniques and built-in functions to find out information about strings.
      3. The len() function is used to return the length of a string.
      4. The index number is used to retrieve a single character from a specified position in a string.
      5. For loops can be used to iterate through some or all of the items in a string.

      Keywords

      • String handling - how programs manipulate text through operations like joining, searching and formatting

      • Index - the location of items or elements in a list, array or string

      • For loop - an iterative statement that will repeat for the length of a given sequence

      Common misconception

      Operations in programs can only be performed on numbers.

      Operations can be performed on different types of data. What the operator does can change depending on the data type it is being used with.

      Teacher tip

      String handling can be used is conjunction with file reading. Extend program to read a text file and process each line using some of the functions in the lesson.

      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 does a for loop do in Python?

      checks if a condition is true or false
      stops the program
      Correct answer: executes a block of code repeatedly for a specific range or sequence
      converts a string to a number

      Q2.
      What does range(5) generate in Python?

      1, 2, 3, 4, 5
      Correct answer: 0, 1, 2, 3, 4
      0, 1, 2, 3, 4, 5
      5, 4, 3, 2, 1

      Q3.
      What is the purpose of an if statement in Python?

      to repeat a block of code
      to stop the program
      to create a loop
      Correct answer: to check a condition and execute code if it's true

      Q4.
      Which of these is not a valid condition in an if statement?

      x == 5
      x <= 5
      Correct answer: `x + 1`
      x < 0

      Q5.
      What does the else part of an if statement do?

      executes code when the condition is True
      executes code when the condition is True
      Correct answer: executes code when the condition is False
      stops the program if the condition is True

      Q6.
      Match the terms with their definitions.

      Correct Answer:for loop,executes a block of code repeatedly for a sequence

      executes a block of code repeatedly for a sequence

      Correct Answer:if statement,checks a condition and executes code if it's True

      checks a condition and executes code if it's True

      Correct Answer:else,executes code when the if condition is False

      executes code when the if condition is False

      6 Questions

      Q1.
      What is the term for a collection of characters enclosed in quotes in Python?

      Correct Answer: string, a string

      Q2.
      What is the index number of the first character in a string in Python?

      Correct Answer: 0, zero

      Q3.
      What will len("Quiz") return?

      0
      1
      2
      3
      Correct answer: 4

      Q4.
      What happens when you use a for loop with a string?

      Each word in the string is printed.
      Correct answer: Each character in the string is processed one by one.
      The string is reversed.
      The string is converted to numbers.

      Q5.
      Which of these is not a valid operation on a string?

      indexing to retrieve characters
      iterating through the string with a loop
      Correct answer: dividing the string by a number
      finding the length of the string

      Q6.
      Which of the following is true about operations in Python?

      Operations can only be performed on numbers.
      Operations can only be performed on strings.
      Operations cannot be performed on either numbers or strings.
      Correct answer: Operations can be performed on both numbers and strings.

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