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: Data Structure of Dict not changing its value as expected
Type: behavior Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: opensource3, zach.ware
Priority: normal Keywords:

Created on 2015-02-24 04:51 by opensource3, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg236476 - (view) Author: Stan (opensource3) Date: 2015-02-24 04:51
Expected the following code to change the value of the variable, it is not, comment are appreciated at this point.



GUMMIE_BEARS = ''

arr2 = { 'GUMMIE_BEARS' : GUMMIE_BEARS }

arr2['GUMMIE_BEARS'] = 'hello world'

print arr2['GUMMIE_BEARS']


print 'and this too' + GUMMIE_BEARS + '<---should be' # point #1


Expected output at point #1 should have 'hello world' contained within the string, it does not however.

# I note this description:
# Mutable variables – such as dictionaries and lists – are passed by reference, 
# and so if your function accepts mutable argument, it may modify the contents of that mutable variable 
# outside the scope of the function.

Thank You.
msg236478 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2015-02-24 05:03
Python's "variables" don't work quite the same as you may be used to thinking of them in other languages.  See http://nedbatchelder.com/text/names.html for a very good description of how Python's name binding works.
msg236487 - (view) Author: Stan (opensource3) Date: 2015-02-24 11:49
Thank You.
History
Date User Action Args
2022-04-11 14:58:13adminsetgithub: 67694
2015-02-24 11:49:28opensource3setmessages: + msg236487
2015-02-24 05:03:46zach.waresetstatus: open -> closed

nosy: + zach.ware
messages: + msg236478

resolution: not a bug
stage: resolved
2015-02-24 04:51:45opensource3create