Another conditional expression candidate (PEP 308)

Andrew Koenig ark at research.att.com
Sun Feb 9 21:50:40 EST 2003


Erik> Evan wrote:
>> x = (if a > 0: 'positive' elif a == 0: 'zero' else: 'negative')

>> The parentheses and 'else:' clause are mandatory.

Erik> I suggested the same in these recent PEP threads as well.

I don't see any reason for the parens to be mandatory.
In particular, I don't see any reason why I should not be
able to write

        foo(if a > 0: 'positive' elif a == 0: 'zero' else: 'negative')

or, for that matter,

        fact = lambda n: if n == 0: 1 else: n*fact(n-1)

I don't think there are any ambiguities here.

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark




More information about the Python-list mailing list