Re:Ask HN: How is the job search coming along for people who...
by Joeboy on Tuesday December 06, 2022 @05:21PM
(#33887965)
Until the second line of your function (in the first example), it's pass by reference, no? It stops behaving like pass-by-reference because you then reuse the name 'd' to create a new object, which has a different id and lives at a different address.
At least, this seems like a coherent mental model of what's happening, to me.
Re:Ask HN: How is the job search coming along for people who...
by rockemsockem on Tuesday December 06, 2022 @05:35PM
(#33888086)
I'm not re-using the name 'd', I'm assigning to the already-existing parameter d. Which if d was indeed a reference would result in the variable passed to the function being changed.
In explaining this I decided to check the Python docs and learned a new piece of terminology "pass by assignment", which is how Python explains its variable passing scheme: https://docs.python.org/3/faq/programming.html#how-do-i-writ...
Here's an example to include the id differences and the fact that a does not take on the value of d:
But, as I've posted elsewhere in this thread, this example will change the contents of 'd' since d itself is not being set, its contents are: