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: It's a bug? Dict
Type: resource usage Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: steven.daprano, xtreak, ymatheus63
Priority: normal Keywords:

Created on 2021-07-03 13:29 by ymatheus63, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg396899 - (view) Author: Matheus Oliveira (ymatheus63) Date: 2021-07-03 13:29
a = {"a":1}

b = a

a["a"]=33

print(b, a)

# {"a":33}, {"a":33}
msg396902 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2021-07-03 13:56
This is not a bug since in this case assignment is referring to the same object and thus mutating one variable reflects change in other variable.

Relevant FAQ : https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x
msg396903 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-07-03 13:59
This is not a bug. Assignment in Python does not make a copy, it creates a second name for the same object.
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88723
2021-07-03 13:59:33steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg396903

resolution: not a bug
stage: resolved
2021-07-03 13:56:40xtreaksetnosy: + xtreak
messages: + msg396902
2021-07-03 13:29:26ymatheus63create