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.
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 fromstartup 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:
| Purpose | Python | OCR Exam Reference Language |
|---|---|---|
| Take three characters from index 1 | text[1:4] | text.substring(1, 3) |
| Take the first three characters | text[:3] | text.left(3) |
| Take the final two characters | text[-2:] | text.right(2) |
| Find the length | len(text) | text.length |
| Convert to uppercase | text.upper() | text.upper |
| Convert to lowercase | text.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.
first_name = "Samira"
surname = "Patel"
username = first_name[0] + surname
middle = surname[1:4]
print(username)
print(middle)
- iteration
- slice
- index
- concatenation
- casting
What is produced by "computer"[2:6]?
- Acomp
- Bmput
- Cmpute
- Dputer
In OCR Exam Reference Language, what does code.substring(1, 2) return when code = "J277"?
- AJ2
- B277
- C27
- DJ277
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.
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.
first_name = "Amina"
surname = "Khan"
# Build, store and display the initials in the required format.
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.
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.