osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

JavaScript's void operator in Python?


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...