Python String Immutability
Multiple Choice Medium
Question
What happens when you run `s = 'hello'; s[0] = 'H'` in Python?
Hint
Strings in Python cannot be changed in place.
Explanation
Python strings are immutable — you cannot assign to an index. s[0] = 'H' raises TypeError: 'str' object does not support item assignment. To change a string, create a new one: s = 'H' + s[1:].
Related Resources
Related Lessons
- Strings
String immutability.
Related Cheatsheets
- Python Cheatsheet
String operations.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.