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

Andrew Dalke adalke at mindspring.com
Fri Feb 7 22:01:44 EST 2003


David Gausebeck:
> The simple example I used in a previous thread is:
>
>    if is_html:
>       extension = "html"
>    else:
>       extension = "txt"
>    print "Processed %s.%s." % (filename, extension)
>
> This could currently also be implemented as
>
>    print "Processed %s.%s." % (filename, is_html and "html" or "txt")
>
> Per the PEP, it would be
>
>    print "Processed %s.%s." % (filename, "html" if is_html else "txt")

This could also currently be written as

     print "Processed %s.%s." % (filename, ["txt", "html"][is_html])

                        Andrew
                        dalke at dalkescientific.com






More information about the Python-list mailing list