1、

>>> a = "gooood"
>>> a.replace("o","x")   ## 将o全部替换为x
'gxxxxd'
>>> a.replace("o","x",1)   ## 指定替换次数
'gxoood'
>>> a.replace("o","x",2)
'gxxood'
>>> a.replace("o","x",3)
'gxxxod'

 

相关文章:

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