【Python面试题】书写一个函数,用于替换某个字符串或几个字符串
函数原型strreplace(str,oldString,newString)
例如:
s = 'Hello World!';
afterReplace = strreplace(s,'World','Tom')
输出结果为:"Hello Tom!"
1
2
3
代码实现:
def strreplace(str,oldString,newString):
str_list = str.split(oldString)
print(newString.join(str_list))
strrepalce('Hello World !','World','Tom')