Message342969
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. |
|
Date |
User |
Action |
Args |
2019-05-21 01:15:40 | steven.daprano | set | recipients:
+ steven.daprano, skypickle |
2019-05-21 01:15:40 | steven.daprano | set | messageid: <1558401340.01.0.437261890816.issue36980@roundup.psfhosted.org> |
2019-05-21 01:15:39 | steven.daprano | link | issue36980 messages |
2019-05-21 01:15:39 | steven.daprano | create | |
|