?: in Python

Steven D'Aprano steve at REMOVETHIScyber.com.au
Thu Dec 15 18:12:30 EST 2005


On Wed, 14 Dec 2005 20:17:28 -0500, Andy Leszczynski wrote:

> I can tell you what is not elegant in the if else: approach. It is 
> logically a one operation while you are forced to use varaible "a" 
> twice. Fundamental flaw IMO.

"Logically" one operation?

def twenty_countries_in_seven_days_bus_tour():
    ...
    if today() == Monday:
        write_postcode_to_mother("We must be in Belgium.")
    else:
        get_back_on_the_bus("Not again!")
    ...


if...else expressions with a single operation are just a special case.
Perhaps a common special case, but still a special case.


-- 
Steven.




More information about the Python-list mailing list