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 字符串替換
相關文章
相關標籤/搜索