Operations for boolean operators


#1

I cant figure out why the logical operation

not not True or False and not True

is True.

Anyone can analyze this for me??

Thanks in advance


#2

Start with the NOT operations, first.

not True   =>  False
not False  =>  True

and

not True   =>  False

so the expression boils down to,

 True or False and False

I won’t go into how this is short-circuited, but follow the chain of precedence. AND is next to be evaluated…

False and False  =>  False

Now the expression boils down to,

True or False  =>  True

To explain short-circuiting, OR (as well as AND) expressions are evaluated from left to right. A True found anywhere in an OR expression will abort the evaluation and yield True as a result. That means any operands to the right of the found True will be ignored.

AND, by the same token will short-circuit on False, as in going from left to right, the first False encountered will abort the evaluation and yield False as a result. Likewise, any remaining operands to the right will be ignored.

Truth Table


#3

Thanks a lot!I was doing the exact same thing but i calculated or before and!
I was soo stuck :slight_smile:


#4

You’re welcome. And now you know to follow precedence rules at all times, since that what the computer is doing.

Python Operator Precedence


#5

Exactly!Its like forgetting the birthday of your wife.You only do it once :stuck_out_tongue:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.