0

I need to replace "cry" with "fly" and "want to" with "will" in the string below.

message ="I want to cry"

I tried this:

print(message.replace("cry", "fly")("want to","will")) 

it doesnt work

0

2 Answers 2

3

You need a separate call to .replace() for each replacement.

print(message.replace("cry", "fly").replace("want to","will")) 
Sign up to request clarification or add additional context in comments.

Comments

0

You can create a dictionary of data that you want to replace

message ="I want to cry"

change_word={"cry":"fly","want to":"will"}

for key,value in change_word.items():
    message=message.replace(key,value)
print(message)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.