小白教程
所有教程
关于
Search
172.69.59.105
172.69.59.105
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 string replace”的源代码
本页内容
上一节:
Python3_string_min
下一节:
Python3_string_rfind
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:replace(old, new [, max])}}[[Category:python3 string|26]] = Python3 replace()方法 = [[python3 string|Python3 字符串]] == 描述 == replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。 == 语法 == replace()方法语法: <sample title="" desc="" lang="python" hererun="1"> str.replace(old, new[, max]) </sample> == 参数 == * old -- 将被替换的子字符串。 * new -- 新字符串,用于替换old子字符串。 * max -- 可选字符串, 替换不超过 max 次 == 返回值 == 返回字符串中的 old(旧字符串) 替换成 new(新字符串)后生成的新字符串,如果指定第三个参数max,则替换不超过 max 次。 以下实例展示了replace()函数的使用方法: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 str = "www.w3cschool.cc" print ("小白教程旧地址:", str) print ("小白教程新地址:", str.replace("w3cschool.cc", "xiaobai.wang")) str = "this is string example....wow!!!" print (str.replace("is", "was", 3)) </sample> 以上实例输出结果如下: <sample title="" desc="" lang="python" hererun="1"> 小白教程旧地址: www.w3cschool.cc 小白教程新地址: www.xiaobai.wang thwas was string example....wow!!! </sample> [[python3 string|Python3 字符串]]
返回至“
Python3 string replace
”。
上一节:
Python3_string_min
下一节:
Python3_string_rfind