For review: PEP 308 - If-then-else expression

William Park opengeometry at yahoo.ca
Sun Feb 9 02:21:43 EST 2003


Andrew Koenig <ark at research.att.com> wrote:
> But what is beautiful and what is ugly is still subjective.
> I think that
> 
>        if x > 0.0:
>            y = math.sqrt(x)
>        else:
>            y = 0.0
> 
> is ugly compared to
> 
>        y = math.sqrt(x) if x > 0.0 else 0.0

The best expression for this is
    y = (x > 0.0) ? math.sqrt (x) : 0.0
So, 
    - YES to '(condition) ? command1 : command2'.
    - NO to '(command1) if (condition) else (command2)'.
-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
Linux solution for data management and processing. 




More information about the Python-list mailing list