python替换特定字符串
来源:互联网 发布:淘宝童装货源 编辑:程序博客网 时间:2024/05/17 04:18
python 字符串替换是python操作字符串的时候经常会碰到的问题,这里简单介绍下字符串替换方法。
python 字符串替换可以用2种方法实现:
1是用字符串本身的方法。
2用正则来替换字符串
下面用个例子来实验下:
a = ‘hello word’
我把a字符串里的word替换为python
1用字符串本身的replace方法
a.replace(‘word’,’python’)
输出的结果是hello python
2用正则表达式来完成替换:
import re
strinfo = re.compile(‘word’)
b = strinfo.sub(‘python’,a)
print b
输出的结果也是hello python
0 0
- python替换特定字符串
- Python 正则表达式替换特定字符为标志的字符串
- 【util】替换字符串中的特定字符串
- sed替换特定行的字符串
- 用特定字符串替换string中的所有特定字串
- Java替换特定字符串中的特定子串
- python字符串的特定操作
- 【python】特定模式抽取字符串
- python 字符串替换
- Python字符串的替换
- python 字符串替换
- python 字符串替换
- python 字符串替换
- python 字符串替换
- 【python】 字符串替换+正则
- Python字符串替换
- python字符串替换
- python字符串替换
- Callable与Future
- LeetCode 26. Remove Duplicates from Sorted Array
- Oracle代码大全.从入门到熟练
- 【phi】
- 百度富文本编辑器的上传图片的路径问题
- python替换特定字符串
- HDU 2660 Accepted Necklace (01背包,dfs)
- HDU5289 Assignment
- 字符串
- Qt读入十六进制数,然后进行计算啥的
- leetcode206~Reverse Linked List
- 3-3 C++ new、delete 补充:多重指针法
- 如何返回到程序列表界面?
- JAVA开发环境搭建