Recall & Review
beginner
What does it mean that strings are immutable in Python?
It means once a string is created, it cannot be changed. Any operation that seems to modify a string actually creates a new string.
Click to reveal answer
beginner
Why can't you change a character in a Python string directly?
Because strings are immutable, their characters cannot be changed one by one. You must create a new string with the desired changes.
Click to reveal answer
intermediate
What happens when you do s = s + 'a' on a string s?
A new string is created by adding 'a' to s, and s now points to this new string. The original string stays unchanged in memory until garbage collected.
Click to reveal answer
intermediate
How does string immutability help with program safety?
Since strings cannot change, they prevent accidental changes and make programs easier to understand and debug.
Click to reveal answer
beginner
Can you modify a string in place in Python? If not, what is the alternative?
No, you cannot modify a string in place. Instead, you create a new string with the changes you want.
Click to reveal answer
What does string immutability mean in Python?
✗ Incorrect
Strings in Python cannot be changed once created; any change creates a new string.
What happens if you try to change a character in a string directly?
✗ Incorrect
Python raises a TypeError because strings are immutable and do not support item assignment.
How can you add a character to a string s in Python?
✗ Incorrect
You create a new string by concatenation; s + 'a' returns a new string.
Why is string immutability useful?
✗ Incorrect
Immutability helps keep data safe and programs easier to understand.
Which of these is NOT true about Python strings?
✗ Incorrect
You cannot change characters directly in a string because strings are immutable.
Explain in your own words what string immutability means and why it matters.
Think about how changing a string is like making a new copy instead of editing the original.
You got /3 concepts.
Describe what happens in memory when you do s = s + 'a' with a string s.
Imagine copying a photo and adding a sticker on the copy, not the original.
You got /3 concepts.