Thursday, 12 September 2013

How to use .replace in python?

How to use .replace in python?

I want to replace a word in a string with another word. Ex.
replaceWord("cool","awesome","Stack overflow is cool.") Output would be:
"Stack overflow is awesome" I don't understand why my code isn't working.
def replaceWord(oldWord,newWord,aStr):
aStr.replace(oldWord,newWord)
return aStr

No comments:

Post a Comment