Skip to main content
Practice

not-operator

---
id: not-operator
title: The not Operator Returning the Opposite
description: Definition and examples of the not operator
tags:
- Boolean
- not operator
- Python
- Programming
sidebar_position: 5
isPublic: false
---

# The not Operator Returning the Opposite

In this lesson, we will take a closer look at the `not` operator introduced earlier.

The `not` operator returns the **opposite** of a Boolean value.

t is primarily used with conditional statements to handle cases where a condition is false or negated.

<br />

## Using the not Operator

The `not` operator returns `False` if the value on its right is `True`, and `True` if the value is `False`.

```python title="Using the not Operator"
is_logged_in = False

# Prints True, the opposite of False
print("not is_logged_in:", not is_logged_in)

if not is_logged_in:
print("Login is required.")

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.