Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8352 > unrolled thread

Re: Interpreting Left to right?

Started byEthan Furman <ethan@stoneleaf.us>
First post2011-06-24 00:14 -0700
Last post2011-06-24 00:14 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Interpreting Left to right? Ethan Furman <ethan@stoneleaf.us> - 2011-06-24 00:14 -0700

#8352 — Re: Interpreting Left to right?

FromEthan Furman <ethan@stoneleaf.us>
Date2011-06-24 00:14 -0700
SubjectRe: Interpreting Left to right?
Message-ID<mailman.356.1308899719.1164.python-list@python.org>
Terry Reedy wrote:
> On 6/24/2011 12:32 AM, Chetan Harjani wrote:
>> x=y="some string"
>> And we know that python interprets from left to right.
> 
> Read the doc. "5.14. Evaluation order
> Python evaluates expressions from left to right. Notice that while 
> evaluating an assignment, the right-hand side is evaluated before the 
> left-hand side."

The example given to me when I had this question:

--> x = x['huh'] = {}
--> x
{'huh': {...}}


As you can see, the creation of the dictionary is evaluated, and bound 
to the name 'x'; then the key 'huh' is set to the same dictionary.  If 
you try that the other way 'round this happens:

 >>> x['huh'] = x = {}
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined

So -- the RHS (right hand side) gets evaluated first, then the LHSs from 
left to right.

~Ethan~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web