Message343050
Thank you for your reply and the lucid explanation.
On Monday, May 20, 2019, 9:15:42 PM EDT, Steven D'Aprano <report@bugs.python.org> wrote:
Steven D'Aprano <steve+python@pearwood.info> added the comment:
Hi Stefan, and welcome.
This is not a help desk, you really should ask elsewhere for explanations of how Python works. There are no bugs here: what you are seeing is standard pass-by-object behaviour.
You are misinterpreting what you are seeing. Python is never pass by reference or pass by value.
https://en.wikipedia.org/wiki/Evaluation_strategy
https://www.effbot.org/zone/call-by-object.htm
*All* function objects, whether strings, ints, lists or numpy arrays, are passed as objects. If you want to make a copy, you have to explicitly make a copy. If you don't, and you mutate the object in place, you will see the mutation in both places.
> Shouldn't the id of each variable be different if they are different instances?
Not necessarily: IDs can be reused. Without seeing the actual running code, I can't tell if the IDs have been used or if they are the same ID because they are the same object.
> Would it possible for the python interpreter/compiler to let me know when a function is going to clobber a variable that is not used in the function or passed to the function or returned by the function
Python never clobbers a variable not used in the function. It may however mutate an object which is accessible from both inside and outside a function.
----------
nosy: +steven.daprano
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue36980>
_______________________________________ |
|
Date |
User |
Action |
Args |
2019-05-21 14:08:11 | skypickle | set | recipients:
+ skypickle, steven.daprano, josh.r |
2019-05-21 14:08:11 | skypickle | link | issue36980 messages |
2019-05-21 14:08:10 | skypickle | create | |
|