Community resourceWorksheet
1CP2-CT-2.1 String length, position and indexing
Part 1 of 8 · 1CP2-CT-2 · Selection, strings and while loops
The opening string worksheet, establishing that positions begin at zero before anything is sliced.
Students will:
- use len() and read a character by its index
- predict the exact output of a short indexing listing
- explain what a negative index selects
- complete and then write a lookup that indexes user input
- debug an off-by-one index rather than blaming the data
Inside: 7 explanation cells, 3 multiple-choice questions, 2 Python tasks, 1 fill-in-the-blanks cell and 2 written answers. 18 marks, about 45 minutes.
Series: 1CP2-CT-2 · Selection, strings and while loops, part 1 of 8.
Shared by Coding PathwayVerified teacher
- 15 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 17 Aug 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
String length, position and indexing
A string is an ordered sequence of characters. Spaces and punctuation are characters too. This worksheet builds the first tools needed to locate and use individual characters.
You already know variables and text input. Here you will predict, explain, complete and then write short Python fragments.
1. Positions begin at zero
For word = "COMPUTE", word[0] is C, word[3] is P, and word[-1] is E. Python uses square brackets for a position. len(word) is 7 because there are seven characters.
A valid positive index runs from 0 to len(word) - 1. Trying word[7] causes a runtime error because that position does not exist.
word = COMPUTE, word[gap 1] gives M, word[-1] gives gap 2, and len(word) gives gap 3.- 2
- 3
- 7
- C
- E
- M
What is len("ice cream")?
- A8
- B9
- C10
- DIt causes an error
2. Predict from a code listing
The same expression can provide a character or help build another value. Read the code without executing it, then predict all three printed lines.
code = "Falcon"
print(len(code))
print(code[1])
print(code[-2])
Which option gives the exact output order?
- A`6`, then `a`, then `o`
- B`6`, then `F`, then `n`
- C`5`, then `a`, then `o`
- D`Falcon`, then `a`, then `o`
Explain why the second output is a rather than F, and why index -2 selects o.
Use zero-based indexing and counting from the end.
Students type their answer here.
3. Complete a lookup
Create tag from the first and final characters of name. With name = "Orchid", the result must be Od. + joins strings; it does not perform arithmetic here.
name = "Orchid"
# Create tag from the first and final characters.
4. Apply it to input
Write a program that inputs a username, stores its length in size, stores its final character in last, and outputs size followed by last on separate lines.
The program will be tested with nova7 and comet. Assume the input is not empty; presence checking is taught later.
# Input username, calculate size and last, then output both.
5. Debug the position, not the data
An off-by-one error uses a position one step away from the intended position. For a string of length n, the last positive index is n - 1, not n. An out-of-range index produces a runtime error; a valid but wrong index produces a logic error.
school = "Riverside" is followed by print(school[len(school)]). Explain why it fails and give a corrected expression for the final character.
Connect the length to the range of valid indexes.
Students type their answer here.
Which expression selects the third character of message?
- Amessage[3]
- Bmessage[2]
- Cmessage[-3]
- Dlen(message[3])
Route forward
You can now treat a string as an ordered structure. Next you will produce substrings, change case and use selected Pearson PLS string methods.