[Tutor] Use of "or" in a lambda expression

boB Stepp robertvstepp at gmail.com
Sun Apr 5 05:45:27 CEST 2015


On Sat, Apr 4, 2015 at 6:55 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> On 04/04/15 22:57, boB Stepp wrote:
>>
>> On Sat, Apr 4, 2015 at 3:35 PM, Alan Gauld <alan.gauld at btinternet.com>
>> wrote:
>>>
>>> He could have done it in various other ways too:
>>>
>>> eg.
>>> lambda : all(print('Hello lambda world!'), sys.exit() )
>>
>>
>> Is this what you meant? Because print will always return False. Or did
>> you actually mean:
>>
>> lambda: any(print('Hello lambda world!'), sys.exit())
>
>
> any() would be more obvious, but in my interpreter
> both any() and all() evaluate both functions before
> testing the results. At least they do once you
> fix the TypeError : they should be in a list/tuple...
>
> lambda : all([print('Hello lambda world!'), sys.exit()] )

Well, now I am curious as to why the "all" form evaluates BOTH
elements. Apparently it does not apply the short-circuit logic we have
been discussing, or it would stop evaluating after the print statement
return.  Why is that?

-- 
boB


More information about the Tutor mailing list