Message319333
I see.
Thanks for the detailed explanations.
Best,
Xiaogang
On 6/11/2018 2:00 PM, Steven D'Aprano wrote:
> Steven D'Aprano <steve+python@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 <report@bugs.python.org>
> <https://bugs.python.org/issue33835>
> _______________________________________
> |
|
Date |
User |
Action |
Args |
2018-06-11 19:45:48 | xgyan | set | recipients:
+ xgyan, steven.daprano, serhiy.storchaka |
2018-06-11 19:45:48 | xgyan | link | issue33835 messages |
2018-06-11 19:45:48 | xgyan | create | |
|