learning python ...

Richard Damon Richard at Damon-Family.org
Tue May 25 07:57:29 EDT 2021


On 5/25/21 12:08 AM, hw wrote:
>
> Are all names references?  When I pass a name as a parameter to a
> function, does the object the name is referring to, when altered by
> the function, still appear altered after the function has returned?  I
> wouldn't expect that ...

If you mutate the object the parameter was bound to, the calling
function will see the changed object. (This requires the object to BE
mutateable, like a list, not an int)

If you rebind that parameter to a new object, the calling function
doesn't see the change, as its name wasn't rebound.

-- 
Richard Damon



More information about the Python-list mailing list