Proposed PEP for a Conditional Expression

thp at thp at
Mon Sep 17 00:19:49 CEST 2001

James_Althoff at wrote:

: Marcin Kowalczyk wrote:
:>    abs = if x>=0 then x else -x
:>    abs = if x>=0: x else: -x
:>looks more readable than
:>    abs = cond(x>=0, lambda:x, lambda:-x)
:>for me.

: That's a fair opinion.  But you have to admit that the last one beats the
: heck out of the first two in terms of implementation issues.

As far as I can tell, it doesn't work if x is a local variable.  Have
you actually tried it?

: And is not nearly as humorous as
:     abs = (x>=0 and [x] or [-x])[0]
: as an available workaround.  ;-)

No question.

Tom Payne

More information about the Python-list mailing list