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

Cameron Simpson cs at zip.com.au
Sun Apr 5 06:22:30 CEST 2015


On 04Apr2015 22:45, boB Stepp <robertvstepp at gmail.com> wrote:
>On Sat, Apr 4, 2015 at 6:55 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
>> 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?

Because the list/tuple is constructed entirely before all() is called. All() 
operates only on the final values.

Cheers,
Cameron Simpson <cs at zip.com.au>

Yesterday, I was running a CNC plasma cutter that's controlled by Windows XP.
This is a machine that moves around a plasma torch that cuts thick steel
plate.  A "New Java update is available" window popped up while I was
working.  Not good. - John Nagle


More information about the Tutor mailing list