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


Groups > comp.lang.python > #8348

Re: Interpreting Left to right?

References <BANLkTimcPAjQP4JJk=OAbrkLFfd2AtndwQ@mail.gmail.com>
Date 2011-06-24 14:59 +1000
Subject Re: Interpreting Left to right?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.351.1308891597.1164.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Jun 24, 2011 at 2:32 PM, Chetan Harjani
<chetan.harjani@gmail.com> wrote:
> x=y="some string"
> And we know that python interprets from left to right. so why it doesnt
> raise a name error here saying name 'y' is not defined?

In most languages, the answer is that the = operator associates right
to left, even though most other operators associate left to right.
(That's how C does it, for instance.) But in Python, I believe it's
actually one operator taking several parameters, because = is not an
expression.

In any case, you can safely treat = as an exception to the
left-to-right rule. There are other exceptions too - note the comments
in http://docs.python.org/reference/expressions.html#summary - there's
not many RTL operators in Python, only those that make sense that way.
:)

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Interpreting Left to right? Chris Angelico <rosuav@gmail.com> - 2011-06-24 14:59 +1000

csiph-web