Python字符串替换
来源:互联网 发布:垂直同步 知乎 编辑:程序博客网 时间:2024/06/06 09:12
Python字符串替换有两种方法:
1. 使用字符串本身的方法
2. 正则表达式
Eg.
1. str=”fuck world”
str.replace(‘world’,’python’,1) #1是替换次数
2. import re
strinfo=re.compile(‘world’)
b=strinfo.sub(‘python’,str)
print b
3. import re
file1=open(‘c:/test.txt’,’r’).read()
file1=re.sub(‘the’,’dpz’,file1)
file2=open(‘c:/test_after.txt’,’wb’)
file2.write(file1)
file2.close()
1 0
- python 字符串替换
- Python字符串的替换
- python 字符串替换
- python 字符串替换
- python 字符串替换
- python 字符串替换
- 【python】 字符串替换+正则
- Python字符串替换
- python字符串替换
- python字符串替换
- python替换特定字符串
- Python 正则替换字符串
- python字符串替换
- 字符串的替换python
- python 字符串替换
- python工具 文件字符串替换
- python替换文件指定字符串
- Python:字符串的多重替换
- Timer vs TimerTask
- GZIP压缩原理分析(07)——第四章 基于gzip的HTTP压缩详解(四01) 章前语
- 面向对象和面向过程的区别
- Android图片缓存之Glide进阶(四)
- 【杭电oj1181】变形课
- Python字符串替换
- beego环境无脑搭建
- 跟我学Redis(4)—Redis配置文件redis.conf
- 图论 最大流 Dinic
- 联想 昭阳 E41-80 i7-6500U 安装 win7 方法说明
- js中replace的用法
- servlet的一些基本原理。
- 求矩阵的最大和路径问题
- web框架学习前复习——html