I thought I understood python's pass-by-reference and pass-by-value processing... can anyone explain what is the difference between pass-by-reference and pass-by-value in python
Asked
Active
Viewed 2,752 times
0
-
1A lot of mutable containers (i.e. lists, sets, class objects, etc) are pass-by-reference-like by default, meaning that they are shallowly copied in such that modifying the shallow copy modifies the original. Pass-by-value means that the values are copied over but the structure does not link to the original variable. You can achieve pass-by-value on a list or similar structure by deep copying, but sometimes you can leverage the shallow copy very efficiently. I don't feel like answering this question fully, so that's my 2 cents that can get you started while you wait for a full answer. – Vadim Mar 03 '21 at 04:43
-
Python is always pass-by-value, never by reference. People just get confused about this due to the fact that **all** values in Python are references to objects. Nonetheless, those references are passed by value. – kaya3 Mar 03 '21 at 04:49
1 Answers
0
Python doesn't really do either. Python does "pass by assignment". Python names are always references to object. When you pass an object, the receiving function's parameter name gets another reference to the object.

Tim Roberts
- 48,973
- 4
- 21
- 30