New
New
Year 10
OCR

String manipulation

I can create a program using string handling techniques.

New
New
Year 10
OCR

String manipulation

I can create a program using string handling techniques.

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


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

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

Equipment

All pupils require 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 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

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: 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

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 "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

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

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

Assessment exit quiz

Download quiz pdf

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

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

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