[Tutor] Advice Please

David Rock david at graniteweb.com
Tue Jun 16 12:36:54 EDT 2020


* Alan Gauld via Tutor <tutor at python.org> [2020-06-16 16:17]:
> On 16/06/2020 09:04, John Weller wrote:
> > Many thanks to all who replied - problem solved!!
> 
> Python is closer to pass by reference than it is to pass by value.
> In python variables(and that includes function parameters) are
> merely names that refer to objects. So a function parameter is
> a name to which an object can be attached.
> 
> If that object is mutable (list, dict, class etc) you can change
> it inside the function and the change will be apparent outside the
> function too. If its immutable a new value will be created and
> assigned to the parameter name but the original variable will
> still refer to the original object.

That's a good callout, Alan.  There's a summary of the OP question in the FAQ, as well:

https://docs.python.org/3/faq/programming.html#how-do-i-write-a-function-with-output-parameters-call-by-reference

-- 
David Rock
david at graniteweb.com


More information about the Tutor mailing list