python学习 ---replace()
来源:互联网 发布:mac键盘pc机能用吗 编辑:程序博客网 时间:2024/05/24 05:48
描述
Python replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。
语法
replace()方法语法:
str.replace(old, new[, max])
参数
old -- 将被替换的子字符串。new -- 新字符串,用于替换old子字符串。max -- 可选字符串, 替换不超过 max 次
返回值
返回字符串中的 old(旧字符串) 替换成 new(新字符串)后生成的新字符串,如果指定第三个参数max,则替换不超过 max 次。
实例
以下实例展示了replace()函数的使用方法: #!/usr/bin/python
str = "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 string
thwas was string example….wow!!! thwas is really string
阅读全文
0 0
- python学习 ---replace()
- Python replace()
- Python中的replace方法
- 批量replace method python
- Python中的replace方法
- Python中的replace方法
- Python replace()方法
- Python replace()方法
- Python string replace 方法
- python字符串replace()方法
- Python中replace方法
- python——replace函数
- python文件的replace替换
- Python学习——str.replace()方法与re.sub()方法对比
- js的学习(replace)
- replace
- Replace
- replace
- Servlet介绍(二)——Servlet中方法介绍
- Linux常用命令
- 匿名函数
- Java重点知识回顾(值传递,多线程,Map)
- [以太坊源代码分析] V. 从钱包到客户端
- python学习 ---replace()
- TBSchedule源码学习笔记-任务处理
- 使用adb命令对设备进行截屏保存到电脑和SDCard
- hiho一下 第180周 Nature Numbers
- 图片拉伸变形
- PHPStartOn
- 导航栏样式、tabBar导航栏
- 每日心得2017.12.11
- 光荣之路:产品测试规范(三)