一、replace()函数
1用字符串本身的replace方法:

a = 'hello word'
b = a.replace('word','python')
print b
 
  • 1
  • 2
  • 3

二、re.sub()

import re
a = 'hello word'
strinfo = re.compile('word')
b = strinfo.sub('python',a)
print b

python 替换字符串的方法replace()、正则re.sub()


 
                    
            
                

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
猜你喜欢
  • 2021-10-17
  • 2021-12-24
  • 2021-12-16
  • 2021-07-28
  • 2021-08-04
  • 2022-12-23
  • 2021-11-16
相关资源
相似解决方案