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 Playground

Tags

languagesyntaxcorebooleanlogicoperator

Related Items