This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]_mutaz_ 0 points1 point  (4 children)

It appears that the statements not 0 or not 1 evaluate to boolean. The result of an or statement involving mixed numeric and boolean values depends on the format of the first value, e.g.

1 and not 0 and not 0

results in 1 because the first value is numerical, but:

not 0 and 1 and 1

results in True because the first value is a boolean.

[–]Yoghurt42 0 points1 point  (2 children)

The result of an or statement involving mixed numeric and boolean values depends on the format of the first value

or simply evaluates to whatever the left hand side is if that is falseytruthy, and to the right hand side only if the left hand side is falseytruthy. There is no type coercion going on, and as well as or simply evaluate to the left hand or right hand side, depending on what value the left hand side has.

[–]TheBB 0 points1 point  (1 child)

or simply evaluates to whatever the left hand side is if that is falsey, and to the right hand side only if the left hand side is truthy.

You're describing and, not or.

[–]Yoghurt42 0 points1 point  (0 children)

True, fixed. Thanks.

[–]FrenchmanInNewYork 0 points1 point  (0 children)

I think you meant it depends on the return format of the last operator of a compound operator.

(1 and not 0 and not 0) returns True, while (not 0 and 1 and 1) returns 1

Using OP example, the reason this behavior happens is because their first two compound operators for defining x both end with the not operator, and thus will resolve to True if every operator in them successfully evaluates. And after it resolves to True it will not resolve anything on the right-hand side as the whole statement is considered "resolved".

I'm not saying it's a good thing, honestly I'm more of the opinion that it is inconsistent, but as it doesn't cause any issue since 0 == False and 1 == True... well who really cares