Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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