-
1.
-
newstring =string.replace(python,Python)
改成
newstring =string.replace('python','Python')
'python' 和'Python' 是字符串要用引号包裹
find没有找到会返回-1,要判断!=-1
你题目的解答代码如下:
string = "Life is short I use python"
if string.find("python")!=-1: # find没有找到会返回-1,要判断!=-1
new_string =string.replace('python','Python')
print(new_string)
else:
print(string)
如有帮助,望采纳!谢谢!