Fix the Bug: Mutating a String
Beginner · Fix the bug · from Python Strings: Create, Access, Slice, and Manipulate Text
From the lesson: Python Strings: Create, Access, Slice, and Manipulate Text
Think about your phone. Almost everything you see on the screen is text: names in your contacts, messages from friends, search results, notifications. Behind the scenes, all of that text is handled by strings.
Read the lessonThis code tries to fix a typo by changing a character directly. But strings are immutable, so it crashes.
Fix the code so it prints:
Hello WorldCreate a new string instead of modifying the old one.
message = "Hello Wurld"
# Fix the typo: change "u" to "o"
message[7] = "o"
print(message)
More Strings exercises
- Build a Greeting with ConcatenationBeginner
- Get the First and Last CharacterBeginner
- Reverse a StringBeginner
- Predict the Slice OutputBeginner
- Check If a Word Is in a SentenceBeginner
- Extract a Domain from an Email AddressBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz