Python Booleans Help

I understand that booleans compare statements for values.
“and” checks if both statements are true
“or” checks if one of them is atleast true
“not” gives the opposite of a statement

not is evaluated first, and is evaluated next, or is evaluated last.

When it comes to solving these exercises, i cant seem to fully remember what each operator does and which seems to come first or last, is there any method to help me remember these easier? It gets quite confusing when it goes " not not and" or " false and not true"
Thanks!

Any and expression that has False in it is False.
Any or expression that has True in it is True.
AND, not negates it.

Try it out in your Terminal for practice.

>>> True and not False
True
>>> False and True
False
>>> False or True
True
>>> not not False and True
False
>>> 
>>> not True or not not False
False
>>> 

https://docs.python.org/3/library/stdtypes.html

1 Like

Thanks! just one question about the not operator.
i understand that the “not true” is negated, which means it cannot be true. However, the “not not false” i’m not sure if im correct. “not not” cancel eachother out meaning it is true that it is false? or am i misunderstanding?
Thanks :slight_smile:

Yep, not negates whatever the value is.

Try it:
(I’m using my terminal on my mac, in Python3):

>>> not False #True
True
>>> not not False   #not(True)
False
>>> not True #False
False
>>> not not True  #not(False)
True
>>> 


My advice is practice until you solidly understand it.
:woman_technologist:

2 Likes