X. Yan <xg...@yorku.ca> added the comment:
I see. Thanks for the detailed explanations. Best, Xiaogang On 6/11/2018 2:00 PM, Steven D'Aprano wrote: > Steven D'Aprano <steve+pyt...@pearwood.info> added the comment: > > Both names "v1" and "v2" refer to the same object. Python does not make > copies of objects on assignment, so if you write: > > a = [] > b = a > > then a and b both refer to the same list object, and the names "a" and "b" > are effectively aliases. This is standard object-sharing behaviour used by > many languages, including Lisp, Ruby, Javascript and Java. > > If you are familiar with languages like Pascal and C++ you are probably > thinking that variables are boxes at fixed memory locations, and assignment > copies values into that box. That is not a good model for Python (and others). > > This is not a bug. If you are unfamiliar with this object model, it can seem > a bit strange at first, but for people who are used to Python, the C and > Pascal model seems strange too. > > Some people call this distinction Values Types (like Pascal and C) versus > Reference Types (like Python, Ruby, Javascript) > > https://softwareengineering.stackexchange.com/questions/314808/why-variables-in-python-are-different-from-other-programming-languages > > ---------- > nosy: +steven.daprano > > _______________________________________ > Python tracker <rep...@bugs.python.org> > <https://bugs.python.org/issue33835> > _______________________________________ > ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33835> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com