Pythonreplace()⽅法
Python replace()⽅法
这是⼀个⽐较使⽤的⼀个字符串替换函数
这个⽤处⼴泛
参考菜鸟教程
描述
Python replace() ⽅法把字符串中的 old(旧字符串)替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。语法
replace()⽅法语法:
参数
old -- 将被替换的⼦字符串。
new -- 新字符串,⽤于替换old⼦字符串。
max -- 可选字符串, 替换不超过 max 次
返回值
返回字符串中的 old(旧字符串)替换成 new(新字符串)后⽣成的新字符串,如果指定第三个参数max,则替换不超过 max 次。
实例
菜鸟教程python函数以下实例展⽰了replace()函数的使⽤⽅法:
实例
#!/usr/bin/python str = "this is wow this is really string"; place("is", "was"); place("is", "was", 3);以上实例输出结果如下:
thwas was wow thwas was really string
thwas was wow thwas is really string

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。