Why is the following bool “True”?


#1

question: why is the following bool “True”?

not not True or False and not True

i thought:

  1. not not True == True
  2. not True == False

so: True or False and False == True and False == False

but system told me it´s True ?! could someone explain me pls?


FAQ: Learn Python - Conditionals & Control Flow - This and That (or This, But Not That!)
#2

Hey Scharc,

I was breaking my head about the same thing, managed to figure it out.

Hope this helps!

not not True or False and not True
Step 1 - (not not True) or False and (not True)
Step 2 - True or (False and False)
Step 3 - True or False
Output - True

there’s an order of operations for boolean operators:
not is evaluated first;
and is evaluated next;
or is evaluated last.


#3

From left to right,

not not True or False and not True

not cannot evaluate not so the second not is evaluated first.

not True  =>  False

Rewriting gives us,

not False or False and not True

not False  =>  True

Rewriting,

True or False and not True

The remaining not is next,

not True  =>  False

Rewriting,

True or False and False

and is evaluated next,

False and False  =>  False

Rewriting,

True or False

which gives True.


#4

hey hawker619,
thank you very much.Thats it.
I guess you are right.


#5

Thanks for the detailed explanation. :slight_smile:


#6

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