PEP 308: A PEP Writer's Experience - PRO
Fredrik Lundh
fredrik at pythonware.com
Sat Feb 8 16:47:58 EST 2003
Paul Rubin wrote:
> I think Andrew Koenig pointed out a third argument which many of us
> had perhaps underestimated: it can prevent bugs. A lot of the
> workarounds attempted for its absence are flat out wrong. He gives an
> example showing finding the maximum of x and y with
>
> x > y and x or y
>
> which looks reasonable and might even pass the initial unit tests of a
> real program, but gives the wrong answer (zero) if x is 0 and y is
> negative. A conditional expression like
>
> x if (x > y) else y
>
> is much harder to get wrong.
in Python, that's spelled:
max(x, y)
</F>
More information about the Python-list
mailing list