Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Types and Branching Booleans

livia salgado
livia salgado
4,407 Points

python basics, booleans with Craig Dennis, minute 6:21 can you elaborate more: (False or False or True) and not

in the minute 6:21 Craig is talking about not true, (False or False or True) and not (True and False) my question is what the NOT is changing here? the False statement made from (True and False)?, True and False is False so not false is true i'm i correct? Gracias!

2 Answers

Not sure I followed you there completely but the not operator (!) is the opposite of what is typed.

TRUE = TRUE

!TRUE = FALSE

TRUE == TRUE is true

TRUE == !TRUE is false (this would be the same as TRUE == FALSE is false.)

When you evaluate it in an IF statement, by default, it is checking to see if your argument is TRUE. If it is then runs the code inside the IF statement. If it evaluates to FALSE then the code inside the IF statement is skipped completely.

In the below example the code will run because TRUE is equal to TRUE so the evaluation statement will return TRUE.

if(TRUE == TRUE):
     run this code

In this example the code will not run because TRUE is NOT equal to !TRUE.

if(TRUE == !TRUE):
     run this code

So here is where we get into the tricky bit, the "or" and "and" operators.
OR means any of the statements must be true.
AND means ALL of the statements must be true.

so..the following would run because TRUE and TRUE and TRUE all evaluate to TRUE

if(TRUE and TRUE and TRUE):
     run this code

This would also run because at least ONE of the statements evaluates to TRUE

if(TRUE or FALSE or FALSE):
     run this code

This would NOT run because none of the statements evaluate to TRUE.

if(FALSE or !TRUE or FALSE):
     run this code

Sorry for the wall of text there but I hope this answers your question. If not please let know and I will try to clarify.

:) -Shawn

eestsaid
eestsaid
1,311 Points

Tripped me at the end Shawn - False or !True or False ... how does that require a statement to evaluate to True to run the code?

Thanks E

(False or False or True) and not (True and False) -> (False or False or True) = (False or True) = True -> (True and False) = False => not (True and False) = True Totally: (False or False or True) and not (True and False) = True and not False = True and True = True