A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/101093.html below:

Conditional operator in Python?

Conditional operator in Python? Conditional operator in Python?Tim Peters tim.one at home.com
Sun Apr 1 13:57:20 EDT 2001
>>     (x and [a] or [b])[0]

[Marcin 'Qrczak' Kowalczyk]
> It computes both a and b.

Nope, it doesn't.  If x is true it evaluates only a; if x false, only b.

> A correct solution is
>     (0 and (lambda: a) or (lambda: b))()

Only if x is always false <wink>, repair the typo, and you're still left with
"the usual" namespace visibility surprises.

> Yes, it is ugly.

They both are.  Use if/then/else, for Parrot's sake.



More information about the Python-list 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