Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8352
| Date | 2011-06-24 00:14 -0700 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: Interpreting Left to right? |
| References | <BANLkTimcPAjQP4JJk=OAbrkLFfd2AtndwQ@mail.gmail.com> <iu1aaq$rni$1@dough.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.356.1308899719.1164.python-list@python.org> (permalink) |
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~
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Interpreting Left to right? Ethan Furman <ethan@stoneleaf.us> - 2011-06-24 00:14 -0700
csiph-web