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.

classification
Title: List similarity relationship
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: PranavSP, terry.reedy, xtreak
Priority: normal Keywords:

Created on 2019-12-04 08:39 by PranavSP, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg357779 - (view) Author: Pranav Pandya (PranavSP) Date: 2019-12-04 08:39
When list is initialized and equated to give the same value as list1=list2=[],

then post initialization list1 & list2 are taken as same values and any changes in list2 are changed in list 1 and so on. 

Thus during initialization if lists are equated, they are taken as same values even if one is changed
msg357781 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-12-04 08:54
This is same as doing the below with list1 getting a reference of list2. Assignments in Python don't copy the value but make a reference. This is not an issue specific to IDLE as tagged and has the same behaviour under a normal REPL.

https://docs.python.org/3/reference/expressions.html#evaluation-order

>>> list2 = []
>>> list1 = list2
>>> id(list2)
4487803136
>>> id(list1)
4487803136
History
Date User Action Args
2022-04-11 14:59:23adminsetgithub: 83147
2020-03-27 16:00:27terry.reedysetcomponents: + Interpreter Core, - IDLE
2019-12-04 10:43:13terry.reedysetstatus: open -> closed
assignee: terry.reedy ->
resolution: not a bug
stage: resolved
2019-12-04 08:54:03xtreaksetnosy: + xtreak
messages: + msg357781
2019-12-04 08:39:40PranavSPcreate