[問題] 傳值問題

作者: woody3724 (woody)   2014-04-13 14:54:54
我的程式碼如右圖 http://i.imgur.com/sIlZPDD.png
執行結果如右圖 http://i.imgur.com/3i7JEd7.png
我明明是把 a 丟入 function x1 中
為什麼在執行完 x1 後
連b的值也會被改變呢
謝謝
( Windows 7 Python 3.3.5 )
作者: LiloHuang (十年一刻)   2014-04-13 15:03:00
a=b 並沒有做拷貝,只是參照,也許 a=b.copy() 是你要的
作者: woody3724 (woody)   2014-04-13 15:05:00
成功了!!! 感謝 原來是pass by reference的概念

Links booklink

Contact Us: admin [ a t ] ucptt.com