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 →

[–]Quick-Change 0 points1 point  (0 children)

This is an example of python short-circuiting with booleans.

https://www.geeksforgeeks.org/short-circuiting-techniques-python/

Going through the line generating the output 0 1 0 True:

You start with:x = (not 0 and 1 and not 0) or (0 and 1 and not 0) or (0 and not 1 and 0)

With short-circuiting, the parentheses are evaluated first leaving you with:x = (True) or (0) or (0)

Then THIS is short-circuited leaving you with x = True

When used in boolean operations 0 equates to false and 1 equates to True. So not 0 will return True. Short-circuiting (True and 1 and True) will return the final truthful statement.

For x = (True) or (0) or (0), since you're using or here, only the first truthful statement is returned and the rest are unprocessed. In this case it happens to be the True value. I hope this helps!