×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Logical and Bitwise NOT Operators on Boolean in Python

Last Updated : April 21, 2025

In Python, not is used for Logical NOT operator, and ~ is used for Bitwise NOT. Here, we will see their usages and implementation in Python.

Logical NOT (not) Operator

Logical NOT (not) operator is used to reverse the result, it returns False if the result is True; True, otherwise.

Example

# Logical NOT (not) operator

x = True
y = False

# printing the values
print("x: ", x)
print("y: ", y)

# 'not' operations
print("not x: ", not x)
print("not y: ", not y)

Output

x:  True
y:  False
not x:  False
not y:  True

Bitwise NOT (~) Operator

Bitwise NOT (~) operator is used to invert all the bits i.e. it returns the one's complement of the number.

Example

# Bitwise NOT (~) operator

x = True
y = False

# printing the values
print("x: ", x)
print("y: ", y)

# '~' operations
print("~ x: ", ~ x)
print("~ y: ", ~ y)

# assigning numbers
x = 123
y = 128

# printing the values
print("x: ", x)
print("y: ", y)

# '~' operations
print("~ x: ", ~ x)
print("~ y: ", ~ y)

Output

x:  True
y:  False
~ x:  -2
~ y:  -1
x:  123
y:  128
~ x:  -124
~ y:  -129

Python Logical and Bitwise NOT Operators on Boolean

Select the correct option to complete each statement about the Logical and Bitwise NOT operators in Python.

  1. The ___ operator is used to negate a Boolean expression in Python (logical NOT).
  2. The ___ operator is used for bitwise negation (flip the bits) in Python.
  3. The expression not True will result in ___.
  4. The result of the bitwise negation of 5 (in binary: 0101) will be ___.

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.