pythonreplace函数不起作⽤的坑字符串的替换函数replace有⼀个坑,
a = "123456"
字符串replace函数
print a
结果还是"123456"
看看replace函数的介绍,
Return a copy of string S with all occurrences of substring
old replaced by new.  If the optional argument count is
given, only the first count occurrences are replaced.
替换之后原来是返回⼀个新的copy,正确的做法是:
a = "123456"
b = a.replace("6","7")
print b

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。