python 字符串替换

字符串替换能够用内置的方法和正则表达式完成。
1用字符串自己的replace方法:html

a = 'hello word'
b = a . replace( 'word' , 'python')
print b

2用正则表达式来完成替换:python

import re
a = 'hello word'
strinfo = re . compile( 'word')
b = strinfo . sub( 'python' , a)
print b
想要了解更多,请看 python 字符串替换
相关文章
相关标签/搜索