-
1.
-
1条回答 默认 最新
- CSDN专家-天际的海浪 2021-11-06 21:13关注
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)
如有帮助,望采纳!谢谢!
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
- ¥15 基于pso参数优化的LightGBM分类模型
- ¥15 安装Paddleocr时报错无法解决
- ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
- ¥50 分布式追踪trace异常问题
- ¥15 人在外地出差,速帮一点点
- ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
- ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
- ¥50 vue router 动态路由问题
- ¥15 关于#.net#的问题:End Function