Python中文
首页
教程
问答
标签
搜索
登录
注册
如何在Python2.7内存中使用临时变量
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我将“haystack”保存在一个临时变量中,但是当我修改“haystack”时,临时变量也会更改。为什么?请帮忙?正常吗?在PHP中我没有这个问题。</p> <pre><code># -*- coding:utf-8 -*- haystack = [1,'Two',3] tempList = haystack print 'TempList=' print tempList iterable = 'hello' haystack.extend(iterable) print 'TempList=' print tempList </code></pre> <p>返回控制台</p> <pre><code>TempList= [1, 'Two', 3] TempList= [1, 'Two', 3, 'h', 'e', 'l', 'l', 'o'] </code></pre> <p>但我没有修改变量“tempList”。<br/> 请帮忙。谢谢。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p><code>tempList</code>和<code>haystack</code>只是绑定到同一个<code>list</code>的两个名称。 复制:</p> <pre><code>tempList = list(haystack) # shallow copy </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
8 回答
如何在python中从数据帧列表中删除引号
9 回答
如何在python中从数据帧创建列表
5 回答
如何在Python中从数据帧创建嵌套的JSON
2 回答
如何在Python中从数据帧显示wordcloud
4 回答
如何在Python中从数据帧的时间戳中删除字符
8 回答
如何在Python中从数据帧绘制简单绘图?
8 回答
如何在python中从数据帧行提取具有特定长度的范围?
8 回答
如何在python中从数据帧设置dict中的值
10 回答
如何在Python中从数据库中获得一个结果
7 回答
如何在python中从数据框中绘制分类条形图
7 回答
如何在Python中从数据框中选择特定细节?
5 回答
如何在python中从数据集中删除unicode
8 回答
如何在python中从数据集中删除某些数值?
4 回答
如何在python中从数据集中选择行
6 回答
如何在Python中从数组中删除元素
6 回答
如何在python中从数组中删除单个倒逗号?
9 回答
如何在python中从数组中删除对象?
8 回答
如何在python中从数组中删除引号
7 回答
如何在python中从数组中删除所有最小值
9 回答