Using the Python not Operator (Overview)
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
00:00
Hello, and welcome to this course on using the Python not
operator. If you’re familiar with conditionals for things like if
statements and while
loops, and you want to express some of your conditions in a much clearer manner, then you should enjoy this course. In this course, we’ll look at the basics of the not
operator, show how it can be used in conditionals and other contexts, then learn the best practices for using it in Python.
00:26
not
is one of the three operators Boolean implemented in Python. The other two are called or
and and
.
00:34
Boolean expressions are used in conditionals to control the flow of the instructions in a Python program. This course is specifically about the not
operator, and it’s based on a similar tutorial by Leodanis Pozo Ramos.
00:49 You can find more tutorials and courses on Boolean operators here at Real Python.
00:56
After completing this course, you will know how the Python not
operator works, how to use the not
operator in both Boolean and non-Boolean contexts, and when to use it and when not to use in your Python programs.
01:12
Let me tell you about the tools I’ll in this course. For Python program files, I use Visual Studio Code with a Dark+ theme. My terminal shell is iTerm2 for macOS. And for my REPL, I use ptpython with its native theme. I’m Howard Francis, and I’m excited to lead you through this course on the Python not
operator. Let’s get started.
Become a Member to join the conversation.