Know if you're actually ready. Take the Python quiz → get your AI readiness report.Take the free test →
Study guide · Python
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"
NoteThe most common string mistake: calling a method without capturing the return value. s.replace("a", "b") does nothing unless you reassign.
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"Notefind() returns -1 if not found. index() raises ValueError. Know which to use when.
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 tipThe 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.Want a person to help?
Struggling with Python? Work 1:1 with a vetted Python tutor on Wyzant. (affiliate link)
Find a Python tutor →