Python String Methods Cheat Sheet for GCSE
String manipulation is one of the most frequently tested programming topics in GCSE Computer Science. This cheat sheet covers every string method and technique you need, with examples you can try yourself.
The basics: accessing characters
Strings in Python are sequences of characters, and each character has an index starting from 0:
name = "Python"
print(name[0]) # P
print(name[5]) # n
print(name[-1]) # n (last character)
print(name[-2]) # o (second to last)
Slicing
Slicing extracts a substring using [start:end]. The start index is included, the end is excluded:
word = "Computer"
print(word[0:4]) # Comp
print(word[4:]) # uter
print(word[:4]) # Comp
print(word[::2]) # Cmue (every 2nd character)
print(word[::-1]) # retupmoC (reversed)
Exam tip: The most common slicing mistake is forgetting that the end index is excluded. "Hello"[0:3] gives "Hel", not "Hell".
Essential string methods
Changing case
text = "Hello World"
print(text.upper()) # HELLO WORLD
print(text.lower()) # hello world
print(text.title()) # Hello World
print(text.capitalize()) # Hello world
print(text.swapcase()) # hELLO wORLD
Finding and counting
sentence = "the cat sat on the mat"
print(sentence.find("cat")) # 4 (index where "cat" starts)
print(sentence.find("dog")) # -1 (not found)
print(sentence.count("the")) # 2
print("cat" in sentence) # True
print(sentence.index("cat")) # 4 (like find, but raises error if not found)
Replacing and stripping
text = " Hello World "
print(text.strip()) # "Hello World" (removes leading/trailing spaces)
print(text.lstrip()) # "Hello World "
print(text.rstrip()) # " Hello World"
message = "I like cats"
print(message.replace("cats", "dogs")) # "I like dogs"
Splitting and joining
csv_line = "Alice,17,A"
parts = csv_line.split(",") # ["Alice", "17", "A"]
print(parts[0]) # Alice
words = ["Hello", "World"]
print(" ".join(words)) # "Hello World"
print("-".join(words)) # "Hello-World"
Checking content
print("hello".isalpha()) # True (only letters)
print("12345".isdigit()) # True (only digits)
print("hello1".isalnum()) # True (letters or digits)
print("HELLO".isupper()) # True
print("hello".islower()) # True
print(" ".isspace()) # True
String formatting
There are several ways to build strings with variables:
name = "Alice"
score = 85
# f-strings (recommended)
print(f"{name} scored {score}%")
# .format() method
print("{} scored {}%".format(name, score))
# Concatenation (avoid for numbers — causes TypeError)
print(name + " scored " + str(score) + "%")
Exam tip: If the exam asks you to output something in a specific format, f-strings are the cleanest way. Remember to convert numbers to strings if using concatenation.
Length
word = "Python"
print(len(word)) # 6
Common mistake: len() is a function, not a method — it's len(word), not word.len().
Iteration
# Loop through each character
for char in "Hello":
print(char)
# Loop with index
for i in range(len("Hello")):
print(i, "Hello"[i])
Common exam patterns
Counting vowels
word = input("Enter a word: ")
vowels = 0
for char in word.lower():
if char in "aeiou":
vowels += 1
print(f"Vowels: {vowels}")
Reversing a string
# Method 1: slicing
reversed_word = word[::-1]
# Method 2: loop
reversed_word = ""
for char in word:
reversed_word = char + reversed_word
Extracting initials
full_name = "John Paul Smith"
parts = full_name.split(" ")
initials = ""
for part in parts:
initials += part[0]
print(initials) # JPS
Practice all of these patterns with hands-on coding challenges — reading about string methods isn't the same as using them under exam conditions.
Want to master Python for GCSE? Our tutoring programs cover every programming topic with expert guidance. Register your interest.