小编Lin*_*ode的帖子

如何在Python 2.7中使用临时变量 - 内存

我将'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'.
求救,谢谢.谢谢.

python memory variables

3
推荐指数
1
解决办法
7450
查看次数

标签 统计

memory ×1

python ×1

variables ×1