首页 > 其他 > 详细

字符串replace

时间:2018-10-29 13:44:14      阅读:157      评论:0      收藏:0      [点我收藏+]
    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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!