【发布时间】:2018-04-26 16:15:05
【问题描述】:
这个问题是关于python是否将其“名称”视为指针或引用,我尚未找到明确的解释。
考虑以下场景:
L = [[][]]
L1 = L[1]
L1 = [1] # Interested in what happens after this line
print L # L = [[], []]
然而, 如果我们把上面感兴趣的行改为L[1] = [1],即下面的代码块:
L = [[][]]
L1 = L[1]
L[1] = [1] # Interested in what happens after this line
print L # L = [[], [1]]
上面的代码块只有第三行不同,我们使用 L[1](直接索引数组)或 L1(我们分配为 L1 = L[1] 的变量)。
那么 L1 和 L[1] 本质上是什么?有什么不同?其中一个是参考,另一个不是?
感谢您解决这个困惑!
【问题讨论】:
标签: python arrays pointers reference