function call questions
Frank Millman
frank at chagford.com
Sat Oct 22 05:05:32 EDT 2016
More information about the Python-list mailing list
Sat Oct 22 05:05:32 EDT 2016
- Previous message (by thread): function call questions
- Next message (by thread): function call questions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
wrote in message news:2853d778-857e-46fc-96a0-8d164c098499 at googlegroups.com... 在 2016年10月20日星期四 UTC+8下午11:04:38,Frank Millman写道: > wrote in message > news:01cfd810-0561-40b1-a834-95a73dad6e56 at googlegroups.com... > > Hi Frank, > > thanks for your kind help. What confused me is at this line: > > >>> r = r.setdefault('b', {}) > > and its previous one > > >>> r = r.setdefault('a', {}) > > When r.setdefault('a',{}) is run, I understand it will return an empty {}. > At this time both r & t reference to {'a':{}}, right? So when "r = > r.setdefault('a',{})" is run, r reference to {} while t keeps the same as > {'a':{}}. > > then comes r.setdefault('b',{}). What hinder me is here. since r has > changed its reference to {}, r.setdefault('b',{}) will return {} again. So > what does this done to t? why at this time t changes to {'a':'b':{}}? > Sorry for my silly here. Thanks > I don't know if you have been following the other posts in this thread. There were some posts from Anssi Saari who was also confused by this, but then yesterday he sent a post saying that he has now 'got it'. I don't think I can do better than quote his explanation of what is happening - """ OK, so what happens is that now t references the dictionary with {'a': {}} and r references the empty dict inside that. So when we assign to r again, it's the empty dict inside t (the one accessed by key 'a') that changes to {'b': {}} and t becomes {'a': {'b': {}}}. """ That is exactly right. Does that help? Frank
- Previous message (by thread): function call questions
- Next message (by thread): function call questions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list