我有一個非常奇怪的Python簡單問題。複製變量改變了原來的?
def estExt(matriz,erro):
# (1) Determinar o vector X das soluções
print ("Matrix after:");
print(matriz);
aux=matriz;
x=solucoes(aux); # IF aux is a copy of matrix, why the matrix is changed??
print ("Matrix before: ");
print(matriz)
...
正如你看到下面的基質matriz
是,儘管事實上,aux
是函數solucoes()
被改變的一個改變。
矩陣前:
[[7, 8, 9, 24], [8, 9, 10, 27], [9, 10, 8, 27]]
矩陣後:
[[7, 8, 9, 24], [0.0, -0.14285714285714235, -0.2857142857142847, -0.42857142857142705], [0.0, 0.0, -3.0, -3.0000000000000018]]
嗨,感謝您的回答=)但我有另一個考慮到這個事實的問題:如果b = 1和a = b,如果我們改變a = 3,則b在python中不會改變。爲什麼?謝謝=) –
因爲你改變'a'指向一個不同的對象(整數'3'),但不改變'b',所以它仍然指向'1'。 – kindall