Message 319325 - Python tracker

Message319325

Author steven.daprano
Recipients serhiy.storchaka, steven.daprano, xgyan
Date 2018-06-11.18:00:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1528740028.77.0.592728768989.issue33835@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2018-06-11 18:00:28steven.dapranosetrecipients: + steven.daprano, serhiy.storchaka, xgyan
2018-06-11 18:00:28steven.dapranosetmessageid: <1528740028.77.0.592728768989.issue33835@psf.upfronthosting.co.za>
2018-06-11 18:00:28steven.dapranolinkissue33835 messages
2018-06-11 18:00:28steven.dapranocreate