Python String Methods: The Complete Exam Reference
Strings are immutable and full of useful methods. Here's what Python exams test — from slicing to f-strings to the most common string methods.
Strings are immutable
You cannot change a string in place. Every string method returns a new string.
s = "hello" s.upper() # returns "HELLO" — doesn't change s print(s) # "hello" — unchanged # Correct: s = s.upper() # reassign print(s) # "HELLO"
Key string methods
Know these methods cold — they appear constantly.
s = " Hello, World! "
s.strip() # "Hello, World!"
s.lower() # " hello, world! "
s.upper() # " HELLO, WORLD! "
s.replace("l","L") # " HeLLo, WorLd! "
s.startswith(" H") # True
s.endswith("! ") # True
s.count("l") # 3
s.find("World") # 9 (index), or -1 if not found
s.index("World") # 9, but raises ValueError if missing
"hello world".split() # ["hello", "world"]
"a,b,c".split(",") # ["a", "b", "c"]
", ".join(["a","b","c"]) # "a, b, c"String formatting — f-strings
f-strings (Python 3.6+) are the modern way to format strings.
name = "Alice"
score = 92.5
print(f"Name: {name}, Score: {score:.1f}")
# "Name: Alice, Score: 92.5"
pi = 3.14159
print(f"{pi:.2f}") # "3.14"
print(f"{1000:,}") # "1,000"
print(f"{'hi':>10}") # " hi"String slicing
Strings support the same slicing syntax as lists.
s = "Python" print(s[0]) # "P" print(s[-1]) # "n" print(s[1:4]) # "yth" print(s[::-1]) # "nohtyP" — reversed print(s[::2]) # "Pto"
Useful string checks
These methods return True or False.
"hello123".isalnum() # True "hello".isalpha() # True "123".isdigit() # True " ".isspace() # True "Hello World".istitle() # True "HELLO".isupper() # True "hello".islower() # True
Exam tip
The most common string mistake in exams is forgetting strings are immutable. `s.upper()` doesn't modify s — you must write `s = s.upper()`. Watch for questions that call a method then print the original variable.
Think you're ready? Prove it.
Take the free Python readiness test. Get a score, topic breakdown, and your exact weak areas.
Take the free Python test →Free · No sign-up · Instant results