I'm trying to reduce and
and get a strange output:
> [and] 2>1, 3>2, put 1, put 2
2
1True
Meanwhile if I put and
between each expression, everything is OK.
> 2>1 and 3>2 and put 1 and put 2
1
2
What's the reason of this difference?
To elaborate on Håkon's comment. The difference is in precedence.
The two statements are equivalent to these:
> [and] (2>1), (3>2), (put 1,(put 2))
2
1True
> (2>1) and (3>2) and (put 1) and (put 2)
1
2
In the first case, it first evaluates put 2
, printing the 2
and returning True
, then the put 1,True
, printing 1True
, returning True
. The whole expression evaluates to True
, but doesn't print anything more.
In the second case, The put 1
evaluates first, printing the 1
and returning True
, then the put 2
evaluates, printing the 2
and also returning True
. Again, the whole expression evaluates to True but doesn't print anything more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With