[Tutor] Use of "or" in a lambda expression
Dave Angel
davea at davea.name
Sun Apr 5 00:40:42 CEST 2015
On 04/04/2015 05:57 PM, 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())
>
>> But the OR style is established as a kind of idiom,
>> not just in Python but several other languages too.
>
> So this is not unusual for Python. BTW, what are some of the other
> languages where this type of expression might be commonly used?
>
>
I don't think I've ever seen it used in Python. But it's quite common
in Perl scripts and bash scripts that I've seen. In the case of bash,
one might do something like:
prog1 && prog2
and prog2 gets executed only if prog1 had a successful completion
--
DaveA
More information about the Tutor
mailing list