wanpython

字符串替换可以用内置的方法和正则表达式完成。
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 字符串替换

分类:

技术点:

相关文章:

  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-10-17
  • 2022-02-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案