码迷,mamicode.com
首页 > 其他好文 > 详细

字符串replace

时间:2018-10-29 14:06:35      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:substring   placed   The   nal   rom   col   return   store   sel   

    def replace(self, old, new, count=None): # real signature unknown; restored from __doc__
        """
        S.replace(old, new[, count]) -> str
        
        Return a copy of S with all occurrences of substring
        old replaced by new.  If the optional argument count is
        given, only the first count occurrences are replaced.
        """
        return ""
name="wesley hello world wesley wesley"
ret=name.replace(wesley,miao)
print(ret)
ret=name.replace(wesley,miao,1)
print(ret)
ret=name.replace(wesley,miao,2)
print(ret)

miao hello world miao miao  #全部替换
miao hello world wesley wesley
miao hello world miao wesley           #count,找到3个,根据count只替换前两个

 

字符串replace

标签:substring   placed   The   nal   rom   col   return   store   sel   

原文地址:https://www.cnblogs.com/wuxi9864/p/9870115.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!