6.10. Boolean Negation

6.10.1. Rationale

  • not logically inverts

6.10.2. Example

>>> not True
False
>>> not False
True

6.10.3. Control Flow

  • not negates (logically inverts) condition

>>> name = None
>>>
>>> if not name:
...     print('Name is empty')
Name is empty
>>> crew = {'Lewis', 'Watney', 'Twardowski'}
>>>
>>> if 'Ivanovich' not in crew:
...     print('You are not assigned to the crew')
You are not assigned to the crew
>>> name = None
>>>
>>> if name is not None:
...     print(name)

6.10.4. Assignments