This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xgyan
Recipients serhiy.storchaka, steven.daprano, xgyan
Date 2018-06-11.19:45:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <8e07dad3-4f9c-8027-8ee0-5341b07062e4@yorku.ca>
In-reply-to <1528740028.77.0.592728768989.issue33835@psf.upfronthosting.co.za>
Content
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>
> _______________________________________
>
History
Date User Action Args
2018-06-11 19:45:48xgyansetrecipients: + xgyan, steven.daprano, serhiy.storchaka
2018-06-11 19:45:48xgyanlinkissue33835 messages
2018-06-11 19:45:48xgyancreate