python字符串替换有两种方法可以实现
1.字符串本身的方法
2.正则表达式
a='hello world'
1.用字符串本身的替换方法
b=a.replace('world', 'test')
输出hello test
2.正则表达式替换
import re
b=re.compile('world').sub('test',a)
python字符串替换有两种方法可以实现
1.字符串本身的方法
2.正则表达式
a='hello world'
1.用字符串本身的替换方法
b=a.replace('world', 'test')
输出hello test
2.正则表达式替换
import re
b=re.compile('world').sub('test',a)
本文标题:字符串替换
本文链接:https://www.haomeiwen.com/subject/rldxvxtx.html
网友评论