python 字符串替换


字符串替换可以用内置的方法和正则表达式完成。
1用字符串本身的replace方法:

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

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

import re
a = 'hello word'
strinfo = re . compile( 'word')
b = strinfo . sub( 'python' , a)
print b
想要了解更多,请看 python 字符串替换


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM