python中字符串的替换

 

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'

 

posted @ 2021-02-25 12:16  小鲨鱼2018  阅读(3102)  评论(0编辑  收藏  举报