Community resourceWorksheet

J277 2.2.3 String manipulation

Part 1 of 5 · J277 2.2.3 · Strings, arrays and functions

String handling in Python, indexed from zero, with slices that stop before their end position.

Students will:

  • index a string and extract a single character
  • take a slice and explain where it stops
  • join strings with concatenation
  • change case and find a string's length
  • build a formatted result from several strings

Inside: 5 explanation cells, 3 runnable Python tasks, 4 multiple-choice questions, 1 fill-in-the-blanks cell and 2 written answers. 17 marks, about 45 minutes.

Series: J277 2.2.3 · Strings, arrays and functions, part 1 of 5.

Shared by Coding PathwayVerified teacher

  • 15 cells
  • About 45 minutes
  • CC BY-SA 4.0
  • Shared 17 Aug 2026
  • Updated 9 Sept 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

String manipulation

A string is a sequence of characters. OCR expects students to manipulate strings, including joining strings and extracting characters or substrings. Python positions are indexed from zero, and a slice stops before its end position.

Multiple choice1 mark

What is the value of word[0] when word = "network"?

  • An
  • Be
  • Cnetwork
  • DAn error

Indexing, slicing and concatenation

  • text[index] selects one character.
  • text[start:stop] selects characters from start up to, but not including, stop.
  • + concatenates strings.
  • len(text) returns the number of characters.

For code = "J277", code[0] is "J", code[1:3] is "27", and len(code) is 4.

OCR Exam Reference Language expresses the same ideas differently:

PurposePythonOCR Exam Reference Language
Take three characters from index 1text[1:4]text.substring(1, 3)
Take the first three characterstext[:3]text.left(3)
Take the final two characterstext[-2:]text.right(2)
Find the lengthlen(text)text.length
Convert to uppercasetext.upper()text.upper
Convert to lowercasetext.lower()text.lower

In OCR's .substring(start, number) notation, the second value is the number of characters, not a Python-style stop index. OCR's .upper and .lower operations are written without brackets; the Python methods use (). Examination questions may show OCR notation even when you choose to answer in Python.

Before running the example below, predict username and middle. Then use the indices in each expression to explain why the first result begins with S and the second contains three characters.

Worked example
first_name = "Samira"
surname = "Patel"
username = first_name[0] + surname
middle = surname[1:4]
print(username)
print(middle)
Fill in the blanks3 marks
Joining strings is called label 1. Selecting one position uses an label 2. Selecting a sequence of characters uses a label 3.
  • iteration
  • slice
  • index
  • concatenation
  • casting
Multiple choice1 mark

What is produced by "computer"[2:6]?

  • Acomp
  • Bmput
  • Cmpute
  • Dputer
Multiple choice1 mark

In OCR Exam Reference Language, what does code.substring(1, 2) return when code = "J277"?

  • AJ2
  • B277
  • C27
  • DJ277
Multiple choice1 mark

In OCR Exam Reference Language, what is stored by label = code.upper when code = "j277"?

  • Aj277
  • Bcode.upper
  • CAn integer
  • DJ277

Supported practice: build a short tag

A robotics club creates a tag from the first three characters of a category and the final two characters of a year. Use slicing to extract both parts, concatenate them and store the result in tag.

For Robotics and 2026, the tag should be Rob26. The checks will also use a different category and year, so build the result from the supplied strings.

Coding task2 marks
category = "Robotics"
year = "2026"

# 1. Slice the required characters from category and year.
# 2. Concatenate the slices and store the result in tag.

Independent practice: format initials

Create initials in the exact form A.K. from the supplied first name and surname. Select the first character of each string, add a full stop after each initial, store the completed string in initials, and display it.

The required punctuation is part of this task, so check the result carefully before submitting.

Coding task3 marks
first_name = "Amina"
surname = "Khan"

# Build, store and display the initials in the required format.
Written answer3 marks

A student expects name[1] to return the first character. Explain the error and state how to select the first character and the final character in Python.

Refer to zero-based indexing and use two correct expressions.

Students type their answer here.

Written answer2 marks

Explain one difference between string concatenation and numerical addition when the + operator is used.

Use an example or describe the result produced by each operation.

Students type their answer here.

Review

You should now be able to concatenate strings, select individual characters, extract substrings, find a string's length and recognise uppercase or lowercase conversion. Translate positions carefully: Python starts at index zero and excludes a slice's stop position, while OCR's .substring() uses a start index followed by the number of characters to take. Spaces and punctuation are characters too, so they affect string length, positions and exact comparisons.