Back
+10 XP
Concept

Replacing Words (.replace())

Swap words or letters inside a string using `.replace(old, new)`:

python
story = "I love Java"
print(story.replace("Java", "Python"))  # "I love Python"

# 37. Replacing Words (.replace()) Swap words or letters inside a string using `.replace(old, new)`: ```python story = "I love Java" print(story.replace("Java", "Python")) # "I love Python" ``` If the target word isn't found, Python shrugs and returns the original text without throwing an error.

Checkpoint

What does `"tacos".replace("hotdog", "pizza")` return?

Practice

You have `bug = "Error 404"`. Replace `"404"` with `"200"` and print the fixed message.

Terminal
01
Tap code blocks below to assemble
Available Blocks