stefan <topjet...@yahoo.com> added the comment: Thank you for your reply and the lucid explanation. On Monday, May 20, 2019, 9:15:42 PM EDT, Steven D'Aprano <rep...@bugs.python.org> wrote:
Steven D'Aprano <steve+pyt...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue36980> _______________________________________ ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36980> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com