not
not flips a value: truthy becomes False and falsy becomes True.
Used in 86 lessons of the course, from 00.02.
not is an operator you write in front of a value. It always returns a bool: True or False.
First Python decides whether the value is truthy or falsy. Falsy values are None, 0, "" (an empty string), [], {} and False. Almost everything else is truthy. Then not flips that result.
That is why the course shows if not value:. You read it as "if there is no value": the block runs when value is None, an empty string, an empty list or any other falsy value. It is shorter than checking each case separately.
not binds tighter than and and or, but looser than comparisons. So not a == b means not (a == b).
print(not [])
Reach for it when: you want to act on something missing or empty, or when you need to invert a condition.
Examples
Common mistake
count = 0
if not count:
print("sin resultados")
else:
print("hay resultados")
print(not count == 0)Why: `0` is falsy, so `not count` is True even though `count` does hold a value. If 0 is valid for you, `not` treats it as "empty".
How to write it: If you only want to detect absence, use if count is None:.
