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只替换前两个