【发布时间】:2013-09-17 16:40:23
【问题描述】:
我想用另一个词替换字符串中的一个词。前任。 replaceWord("cool","awesome","Stack overflow is cool.") 输出会是:"Stack overflow is awesome" 我不明白为什么我的代码不起作用。
def replaceWord(oldWord,newWord,aStr):
aStr.replace(oldWord,newWord)
return aStr
【问题讨论】:
-
看看这个
str.replace(old, new[, max]),max -- If this optional argument max is given, only the first count occurrences are replaced
标签: python