Editor

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 lesson

This 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 World

Create 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

All Python exercises · 50 practice problems · Python Fundamentals quiz