A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2005-September/056846.html below:

[Python-Dev] Conditional Expression Resolution

[Python-Dev] Conditional Expression Resolution [Python-Dev] Conditional Expression ResolutionGuido van Rossum guido at python.org
Fri Sep 30 03:21:53 CEST 2005
After a long discussion I've decided to add a shortcut conditional
expression to Python 2.5.

The syntax will be

    A if C else B

This first evaluates C; if it is true, A is evaluated to give the
result, otherwise, B is evaluated to give the result.

The priorities will be such that you can write

    x = A if C else B
    x = lambda: A if C else B
    x = A if C else B if D else E

But you'd have to write

    if (A if C else B):
    [x for x in seq if (A if C else B)]
    A if (X if C else Y) else B
    (A if C else B) if D else E

Note that all these are intentionally ugly. :)

In general, 'if' and 'else' bind less tight than everything except lambda.

We will adjust the syntax of what goes inside an 'if' to disallow
lambda; currently

    if lambda: x:

is accepted but quite useless (it's always true) so this will be disallowed.

Flames, pleas to reconsider, etc., to /dev/null.

Congratulations gracefully accepted.

It's still my language! :-)

--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4