Using the Python not Operator

Howard Francis
Howard Francis 14 Lessons 30m basics python

Python’s not operator allows you to invert the truth value of Boolean expressions and objects. You can use this operator in Boolean contexts, such as if statements and while loops. It also works in non-Boolean contexts, which allows you to invert the truth value of your variables.

Using the not operator effectively will help you write accurate negative Boolean expressions to control the flow of execution in your programs.

In this course, you’ll learn:

  • How Python’s not operator works
  • How to use the not operator in Boolean and non-Boolean contexts
  • How to use the operator.not_() function to perform logical negation
  • How and when to avoid unnecessary negative logic in your code

What’s Included:

Downloadable Resources:

About Howard Francis

Howard is an avid Pythonista and records video courses for Real Python. He has been teaching beginning programming at the college level for over 20 years in C++, Java, C#, and most recently Python.

» More about Howard

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

« Browse All Courses