82.5k views
5 votes
write python code that prints a string made up of the string stored in a variable sentence with all instances of the word 'idea' replaced with the word 'thought'. assume the sentence variable has already been init;azed

1 Answer

6 votes

Answer:

new_sentence = sentence.replace('idea', 'thought')

print(new_sentence)

Step-by-step explanation:

This code creates a new string new_sentence by replacing all instances of the substring 'idea' with the substring 'thought' in the original string sentence. The replace() method returns a new string with the replacements made, and this new string is then printed to the console using the print() function.

User Dan Gerhardsson
by
7.9k points