Python replace()方法
来源:互联网 发布:智慧树网络课程好过吗? 编辑:程序博客网 时间:2024/06/05 17:44
【注】本文转自http://www.w3cschool.cc/python/att-string-replace.html
描述
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方法
- Cgi入门教程之:10 email子过程
- UVA 11624.Fire(广搜)
- 遍历Jenkins所有项目的配置
- canada goose parka-714
- LeetCode-Subsets
- Python replace()方法
- UNP卷1:第十四章(高级I/O函数)
- LaTeX完整例子_参考文献、图、表和公式
- 求哈弗曼编码
- hdu 1874 dijsktra(mlogn) +bellmanford
- nginx send back content post by client
- 设置字体相关命令
- <图形图像,动画,多媒体> 读书笔记 --- 音效
- [HDU 4776 Ants] Trie异或+预处理