not
KeywordPython 2.0+Beginner
Logical NOT operator; inverts a boolean value
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
print(not True) print(not False) # Negating conditions x = 5 if not x > 10: print("x is not greater than 10") # Checking absence fruits = ["apple", "banana"] if "cherry" not in fruits: print("No cherry available") # not with falsy values print(not 0) print(not "") print(not None) print(not [])
'not' returns True if the value is falsy, False if truthy. It always returns a boolean, unlike 'and' and 'or'.
Try in PlaygroundTags
languagesyntaxcorebooleanlogicoperator
Related Items
and
Keyword
Logical AND operator; returns True if both operands are true
or
Keyword
Logical OR operator; returns True if at least one operand is true
if
Keyword
Starts a conditional statement; executes block only if condition is true
bool()
Built-in Function
Converts a value to a Boolean (True or False)
__bool__
Dunder Method
Called by bool(); defines truthiness of the object