And C expression bool a:? B is similar, but bool and a or b, when a is false, not as a C expression bool:? B work as
and-or trick should be encapsulated into a function:
def choose(bool, a, b): return (bool and [a] or [b])[0]Since [a] is a non-empty list, it is never false. A is 0 or even '' or other false value, the list [a] is true, because it has an element.
Category Quantity: Interview classic> Python
Author: alien invasion
Links: http://www.pythonheidong.com/blog/article/45/
Source: python black hole net www.pythonheidong.com