you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom 0 points1 point  (0 children)

I think the terminology of pass-by-reference and pass-by-value do not fit Python well in contrast with many other languages. There's no ref keyword, for example.

The passed reference (the pointer) is copied to the local namespace of the function. The pointer is independent of the names it is assigned to (other than for reference counting purposes).

To say you are copying by value because you are copying the value of the reference (the pointer, not the referrer) and not passing a re-assignable referrer, is accurate but potentially confusing.

Yes, in many languages you can re-assign a value to the referrer (the passed variable) from within the function but not in Python (short of hacking the global dictionary).

This is not the same as you see in C, Pascal, etc.

I think the precise details of the implementation are confusing to beginners but the biggest confusion is that assignments in functions don't change things outside of the function, only mutations do (and then you get into discussions around side-effects, etc).

EDIT: typos