KS3 & GCSE Computing · GCSE

String Slicing and Indexing in Python: GCSE Computer Science Guide

Master string slicing and indexing in Python for GCSE Computer Science: how index notation works, how to extract substrings, and common slice patterns you must know.

Duke Harewood — author of AI Tutors for Key Stage 3Updated 3 min read

On this page

Short answer

In Python, every character in a string has an index starting at zero. Indexing lets you retrieve a single character; slicing lets you extract a portion of the string using a start and stop position. Both are essential for GCSE string manipulation questions.

At a glance

Key stage
GCSE
Subject
Computing
Type
Guide
For
Students
Read time
3 min
Last updated
6 August 2026

Where this fits

  1. Key Stage 3Years 7–9
  2. GCSEYears 10–11This article
This article is aimed at GCSE (Years 10–11), the stage after Key Stage 3 (Years 7–9).

How does indexing work in Python strings?

Python numbers the characters in a string from left to right, starting at index 0. The last character is at index len(string) - 1.

word = "COMPUTING"
#        C  O  M  P  U  T  I  N  G
#        0  1  2  3  4  5  6  7  8

To access a single character, place the index in square brackets:

print(word[0])   # C
print(word[4])   # U
print(word[8])   # G

This is called indexing or subscript notation. If you use an index that does not exist (e.g. word[9] for a 9-character string), Python raises an IndexError.

What are negative indices and when do you use them?

Python also supports negative indices, counting backwards from the end of the string:

word = "COMPUTING"
#        C   O   M   P   U   T   I   N   G
#       -9  -8  -7  -6  -5  -4  -3  -2  -1
print(word[-1])   # G  (last character)
print(word[-2])   # N  (second to last)
print(word[-9])   # C  (same as word[0])

Negative indexing is particularly useful when you do not know the length of a string — word[-1] always gives the last character, regardless of length.

How does slicing work?

Slicing extracts a portion of a string using the syntax string[start:stop]. The slice includes the character at start but excludes the character at stop (stop is non-inclusive):

word = "COMPUTING"

print(word[0:4])   # COMP  (indices 0, 1, 2, 3 — stop 4 excluded)
print(word[4:9])   # UTING (indices 4, 5, 6, 7, 8)
print(word[2:7])   # MPUTI

A key rule: word[start:stop] always gives stop - start characters (when both indices are within the string and start < stop).

What are the common slice shorthand patterns?

Python allows you to omit either the start or stop index:

Slice Meaning Example with "COMPUTING"
word[:4] From index 0 up to (not including) 4 "COMP"
word[4:] From index 4 to the end "UTING"
word[:] A copy of the whole string "COMPUTING"
word[-3:] Last 3 characters "ING"
word[:-3] Everything except the last 3 "COMPUT"

These shorthands appear frequently in GCSE exam questions and come up constantly in the GCSE programming project.

How does the step parameter work in slicing?

The full slice syntax is string[start:stop:step]. The step controls how many positions to advance between each character selected:

word = "COMPUTING"

print(word[0:9:2])   # CMTNG  (every other character: 0, 2, 4, 6, 8)
print(word[::3])     # CUG    (every 3rd character: 0, 3, 6)
print(word[::-1])    # GNITUPMOС  (reversal: step of -1)

word[::-1] is the classic Pythonic way to reverse a string. It is a favourite GCSE exam trick — remember it.

What string manipulation operations combine with slicing?

At GCSE, slicing works alongside other string operations:

name = "John Smith"

first = name[:4]              # "John"
last = name[5:]               # "Smith"
upper_first = name[:4].upper()  # "JOHN"
length = len(name)            # 10

# Checking characters
if name[0] == "J":
    print("Name starts with J")

# Concatenation
initials = name[0] + name[5]  # "JS"

The .upper(), .lower(), .find(), .replace(), and len() functions all work seamlessly with sliced substrings because slicing always returns a new string.

Frequently asked questions

Why does word[0:4] give 4 characters when index 4 is excluded?

This is the classic "fence-post" puzzle. The indices 0, 1, 2, 3 give four characters — count them: word[0], word[1], word[2], word[3]. The 4 in word[0:4] is the stopping point, not the last index included. Python's convention is that start is inclusive and stop is exclusive. One benefit: len(word[a:b]) is always b - a, which makes arithmetic much simpler.

What happens if the start is greater than or equal to the stop in a slice?

Python returns an empty string rather than raising an error. For example, "COMPUTING"[5:2] returns "". This is different from indexing, where an out-of-range index raises an IndexError. Python also silently clamps slice indices that exceed the string length — "ABC"[0:100] returns "ABC" rather than crashing.

Is string indexing the same in pseudocode at GCSE?

Most GCSE awarding bodies use 1-based indexing in their pseudocode (the first character is at index 1, not 0). AQA's pseudo-function SUBSTRING(string, start, length) extracts a substring starting at position start with the given length. Always check the specific convention your exam board uses — Python uses 0-based indexing while pseudocode often uses 1-based. This difference trips up many students.

Does slicing modify the original string?

No. Strings in Python are immutable — they cannot be changed in place. Slicing (and all other string operations) creates a new string object; the original is untouched. To "modify" a string, you assign the result to a new variable: new_word = word[1:] gives a new string without the first character, but word itself is unchanged.


For Socratic KS3 tutoring and free GCSE flashcards, see aitutors.me.

Key terms

  • indexing
  • subscript notation
  • excludes
  • immutable

Sources