在C++里pass by value和pass by reference是兩個很容易區分的東西。但是在python中,讓我有點糊涂,其實Python是“pass by assignment”。
舉個例子:
>>> a=[1,2,3]
>>> b=a
>>> b
[1, 2, 3]
>>> a.append(4)
>>> b
[1, 2, 3, 4]
>>> a=[1]
>>> b
[1, 2, 3, 4]
可以看到,a和b一開始都是bind to [1,2,3]這一個list object。這個list object的變化(append 4)使得a和b都發生了變化。但是,當a bind to another object [1], b is still pointing to the original object, and the original object doesn't change.
This property properly determines when calling a function, how the parameter is passed. Personally I would understand that as "pass by object".
Reference
stack overflow and quora