米脂
a = b在 Python 中的作用存在误解。这并不意味着“修改a数据,使其与b数据相同”。相反,它的意思是:“从现在开始,使用变量名a来引用由变量引用的相同数据b”。请参阅此示例:data = ['a', 'b', 'c']x = data[0] # x is now 'a', effectively the same as: x = 'a'x = 'b' # x is now 'b', but `data` was never changeddata[0] = 'm' # data is now ['m', 'b', 'c'], x is not changeddata[1] = 'm' # data is now ['m', 'm', 'c'], x is not changed原始代码也会发生同样的情况:for i in arr[0]: # i is now referencing an object in arr[0] i = 1 # i is no longer referencing any object in arr, arr did not change