JavaScript's void operator in Python?

Python python at invalid
Sun Feb 2 13:53:44 EST 2020


Stefan Ram wrote:
> Jon Ribbens <jon+usenet at unequivocal.eu> writes:
>> On 2020-02-02, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>>> void( ( print( 2 ), print( 3 )))
>>> 2
>>> 3
>> I'm not sure why you'd want to - but "None and foo" is an expression
>> that will return None regardless of the value of "foo".
> 
>    Yes, but it also does not evaluate the second operand. I.e.,
> 
> None and( print( 2 ), print( 3 ))
> 
>    prints nothing at all.
> 
>    I was looking for something that still evaluates and then
>    maps the value obtained to None.

( (print(2), print(3)), None)[1]

I wonder why one would need such a thing, though...


More information about the Python-list mailing list