Skip to content
Menu

Year 10 (ages 14–15, Grade 9 in the US) · Computing · GCSE programming · Lesson 6

String handling

Working with strings in Python: length, indexing from zero, slicing, upper and lower case, concatenation, looping through characters, and character codes with ord() and chr().

Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

Whiteboard video lesson: String handling

8-minute video lesson

Teaching, worked examples and 20 practice questions solved step by step.

Watch free for a month

What your child will learn

  • Find the length of a string
  • Use indexing and slicing
  • Change case and join strings
  • Use ord() and chr()

The method

  1. len(s) gives the number of characters.
  2. Indexes start at 0: s[0] is the first character.
  3. s[a:b] slices from a up to, but not including, b.
  4. s.upper(), s.lower(); ord() → code, chr() → character.

Key words: string, index, slicing, length, concatenation.

Worked examples

Worked examples from the lesson, with every step.

Question 1

s = "COMPUTER". What is len(s), s[0] and s[3]?

  1. Step 1: 8 characters
  2. Step 2: s[0] = C; s[3] = P

Answer: 8, C, P

Question 2

s = "COMPUTER". What is s[1:4]?

  1. Step 1: 1, 2, 3 (not 4)
  2. Step 2: O, M, P

Answer: OMP

Question 3

What does this output? c:name = "ada lovelace" c:print(name.upper()[0:3])

  1. Step 1: "ADA LOVELACE"
  2. Step 2: first 3 characters

Answer: ADA