Pages

May 12, 2015

Call by assignment in Python

When passing a mutable object (list, dictionary, etc.) to a function, it works like "call by reference" that the object will be shared.

When passing a immutable object (int, tuple) to a function, it works like "call by value" that it pass a copy of the original object to a function.

See more detail:
[1] https://docs.python.org/3/faq/programming.html#how-do-i-write-a-function-with-output-parameters-call-by-reference
[2] http://stackoverflow.com/questions/986006/how-do-i-pass-a-variable-by-reference

No comments:

Post a Comment