Python replace()方法
来源:互联网 发布:李荣浩戒烟知乎 编辑:程序博客网 时间:2024/05/16 13:43
http://www.w3cschool.cc/python/att-string-replace.html
Python replace()方法
描述
Python replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。
语法
replace()方法语法:
str.replace(old, new[, max])
参数
- old -- 将被替换的子字符串。
- new -- 新字符串,用于替换old子字符串。
- max -- 可选字符串, 替换不超过 max 次
返回值
返回字符串中的 old(旧字符串) 替换成 new(新字符串)后生成的新字符串,如果指定第三个参数max,则替换不超过 max 次。
实例
以下实例展示了replace()函数的使用方法:
#!/usr/bin/pythonstr = "this is string example....wow!!! this is really string";print str.replace("is", "was");print str.replace("is", "was", 3);
以上实例输出结果如下:
thwas was string example....wow!!! thwas was really stringthwas was string example....wow!!! thwas is really string
0 0
- Python中的replace方法
- Python中的replace方法
- Python中的replace方法
- Python replace()方法
- Python replace()方法
- Python string replace 方法
- python字符串replace()方法
- Python中replace方法
- Python replace()
- replace方法
- Python常用方法记录——replace()、split()
- reload 方法 replace 方法
- 批量replace method python
- python学习 ---replace()
- Python学习——str.replace()方法与re.sub()方法对比
- javascript 中的replace方法
- JavaScript 中的replace方法
- javascript 中的replace方法
- BlueDroid代码分析之L2CAP
- FLASK-WTF,为表单添加样式。
- flash as3读写8字节64位数据ByteArray
- android:clipToPadding和android:clipChildren
- POJ 计算几何入门题目推荐(转)
- Python replace()方法
- Android打开系统相册的问题
- 编程珠玑之第二章习题9
- Nginx 中的 upstream 与 subrequest 机制
- java中的随机数(Math.random()),以及如何产生一个类似于[21,77]区间的随机数。
- Hadoop技术原理总结#
- 加载依赖的jar包在命令行编译和运行java文件
- PHP添加CURL扩展库
- jQuery 使页面滚动到某个 div 处