How exactly does not work, especially if we write not not?


#1

Question

How exactly does not work, especially if we write not not?

Answer

The basics are simple enough, but like a lot of things we’ve learned so far, can become pretty tricky if we add onto them! The not operator is no exception!
Something that may help us when determining if a statement is True or False is breaking it down into its simplest parts and then solving the whole thing. Take a look below for an example:
bool_complicado = not not 3 ** 2 + 10 != 60
First let’s do the stuff after the 2 nots to make life easier. Step by step, that’d look like:

bool_complicado = not not 9 + 10 != 60
bool_complicado = not not 19 != 60
bool_complicado = not not True

Great! Now we see it in a much simpler form and can apply those pesky nots. Always apply the inner-most not first.

bool_complicado = not False
bool_complicado = True

Notice how not True became False on the first line above, and then not False is as much as we could break it down before writing the final answer!


FAQ: Learn Python - Conditionals & Control Flow - Not