Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jussi Piitulainen Newsgroups: comp.lang.python Subject: Re: Python variable assigning problems... Date: Fri, 11 Dec 2015 20:27:18 +0200 Organization: A noiseless patient Spider Lines: 40 Message-ID: References: <4b28ee3d-47b3-40ef-b48e-abff720635ed@googlegroups.com> <0098ce4a-966b-41df-bf06-352ad451134f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="305c68510616a2e7ac08bcd2ff1598bd"; logging-data="30000"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+U/BFb135YJCy6N8711hf5PVW9NHm76PU=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:tSDbhE3KGswGyR/noFM3q/67gjI= sha1:HXTA6hec02Ln9Pqh3hViuhB5Tk8= Xref: csiph.com comp.lang.python:100286 ICT Ezy writes: > On Friday, December 11, 2015 at 8:40:18 AM UTC-8, Ian wrote: >> >> No, it actually happens left to right. "x = y = z = 0" means "assign >> 0 to x, then assign 0 to y, then assign 0 to z." It doesn't mean >> "assign 0 to z, then assign z to y, etc." This works: >> >> >>> d = d['foo'] = {} >> >>> d >> {'foo': {...}} >> >> This doesn't: >> >> >>> del d >> >>> d['foo'] = d = {} >> Traceback (most recent call last): >> File "", line 1, in >> NameError: name 'd' is not defined > > Deat Ian, > Thank you very much your answer, but > above answer from Robin Koch and your answer is different. What's the > actually process here? I agree with Robin Koch, but your answer is > correct. Pl explain differences ? Python language reference, at 7.2 Assignment statements, says this: # An assignment statement evaluates the expression list (remember that # this can be a single expression or a comma-separated list, the latter # yielding a tuple) and assigns the single resulting object to each of # the target lists, from left to right. To simplify a bit, it's talking about a statement of this form: target_list = target_list = target_list = expression_list And it says what Ian said: the value of the expression is assigned to each target *from left to right*.