Hmm... An idea: if a,b==c,d:

Richard Dillingham shadowlord13_1 at yahoo.com
Mon Nov 18 18:32:21 EST 2002


"Erik Max Francis" <max at alcyone.com> wrote in message
news:3DD974C6.CD626D0A at alcyone.com...
> Richard Dillingham wrote:
>
> > Kind of like we have multiple assignments in a line (oldx,oldy=x,y),
> > what do
> > you think of the ability to have multiple tests in an if statement
> > with only
> > one == or >=.
> >
> > This would mean that lines like the following:
> > if posx>=coords[0] and posy>=coords[1] and posx<=coords[2] and
> > posy<=coords[3]:
> >
> > Could be rewritten like so:
> > if posx,posy>=coords[0],coords[1] and posx,posy<=coords[2],coords[3]
>
> The obvious problem is that this syntax already has a meaning in Python,
> and it's not what you think.
>
> a, b == c, d
>
> creates a tuple of length three, the second element of which is the
> result of the comparison b == c; that is, it's
>
> (a, (b == c), d).
>
> Even if you group parentheses to avoid this, you get
>
> (a, b) == (c, d)
>
> which also already has a meaning; it's a comparison of the tuples, not
> the pairwise comparison of the elements.
>
> --
>  Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
>  __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
> /  \ Who's not sat tense before his own heart's curtain?
> \__/ Rainer Maria Rilke
>     Maths reference / http://www.alcyone.com/max/reference/maths/
>  A mathematics reference.

As I have asked everyone else that brings up that point, then why does the
following fail (Using Python 2.2.2)?

if a,b==c,d: print a
  File "<input>", line 1
    if a,b==c,d: print a
        ^
SyntaxError: invalid syntax





More information about the Python-list mailing list