【发布时间】:2013-06-08 00:33:33
【问题描述】:
我将 '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
在控制台返回
TempList=
[1, 'Two', 3]
TempList=
[1, 'Two', 3, 'h', 'e', 'l', 'l', 'o']
但我没有修改变量“tempList”。
请帮忙。谢谢。
【问题讨论】: