在其中,
str.replace您还可以传递一个可选的3rd参数(
count),该参数用于处理已完成的替换次数。
In [20]: strs = 'a;b;c;d'In [21]: count = strs.count(";") - 1In [22]: strs = strs.replace(';', ', ', count).replace(';', ' & ')In [24]: strsOut[24]: 'a, b, c & d'帮助
str.replace:
S.replace(old, new[, count]) -> stringReturn a copy of string S with all occurrences of substringold replaced by new. If the optional argument count isgiven, only the first count occurrences are replaced.



