字符串的替換函數replace有一個坑,
a = "123456"
a.replace("6","7")
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