我将'haystack'保存在临时变量中,但是当我修改'haystack'时,临时变量也会改变.为什么?请帮忙?这是正常的?在PHP我没有这个问题.
# -*- coding:utf-8 -*-
haystack = [1,'Two',3]
tempList = haystack
print 'TempList='
print tempList
iterable = 'hello'
haystack.extend(iterable)
print 'TempList='
print tempList
Run Code Online (Sandbox Code Playgroud)
在控制台中返回
TempList=
[1, 'Two', 3]
TempList=
[1, 'Two', 3, 'h', 'e', 'l', 'l', 'o']
Run Code Online (Sandbox Code Playgroud)
但我没有修改变量'tempList'.
求救,谢谢.谢谢.