Python replace()方法,pythonreplace方法,描述Python r
Python replace()方法,pythonreplace方法,描述Python r
描述
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
Python replace()方法
相关内容
- python ConfigParser读取配置文件,及解决报错ConfigParser.M
- Python中PIL及Opencv转化,pythonpilopencv,转载:http://
- python学习,,1。pycharm在
- python爬虫笔记之re.IGNORECASE,, re.IGNO
- pip 升级 Appium-Python-Client,,第一种方法:pip
- 怎么做到Python file重复写入之前的内容不被后写入的覆
- 四十六 Python分布式爬虫打造搜索引擎Scrapy精讲—elas
- Centos 6.5 python 2.6.6 升级到 2.7.3,并安装easy_install和pip工
- 【Python】使用Microsoft Azure的人脸API进行本地图片情绪识
- python2除法保留真实结果,python2除法保留,python2和py
评论关闭