【发布时间】:2014-01-09 13:36:46
【问题描述】:
我尝试使用 python 列表进行跟踪
a = [1,2,3]
id(a)
3072380812L
a += [1]
print id(a)
3072380812L # Same id, which means original list is modified
a = a + [1]
print id(a)
146238764 # Different id, which means new list is allocated and assigned to a
为什么 python 列表的“var += value”和“var = var + value”之间有这种区别?
【问题讨论】:
标签: python