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

Erik Max Francis max at alcyone.com
Mon Nov 18 18:16:22 EST 2002


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.



More information about the Python-list mailing list