Editor

Replace All Occurrences

Beginner · Write the code · from Every Python String Method Explained with Examples

From the lesson: Every Python String Method Explained with Examples

Strings in Python come with a toolbox of built-in methods. These methods let you change case, remove extra spaces, search for words, split text apart, and much more.

Read the lesson

Replace every occurrence of "JavaScript" with "Python" in the sentence below and print the result.

Expected output:

I love Python. Python is great. Learning Python is fun.
sentence = "I love JavaScript. JavaScript is great. Learning JavaScript is fun."
# Replace JavaScript with Python and print it

More string methods exercises

All Python exercises · 50 practice problems · Python Fundamentals quiz