【发布时间】:2022-01-06 22:18:28
【问题描述】:
我无法理解,为什么我在以下两种情况下得到不同的值:
-案例1:
def myfunc(a,b,c):
xx = a+b
yy = b+c
return xx, yy
q,w = myfunc(1,2,3)
print(q,w)
Output 1: 3 5
-案例2:
import numpy as np
q=w=np.zeros(3)
def myfunc(a,b,c):
xx = a+b
yy = b+c
return xx, yy
for i in range(3):
q[i],w[i] = myfunc(1,2,3)
print(q,w)
Output 2: [5. 5. 5.] [5. 5. 5.]
在第二种情况下,两个数组的条目都等于 5。谁能解释一下,为什么?
【问题讨论】: