Home » Python

Python operator.not_() Function with Examples

Python operator.not_() Function: Here, we are going to learn about the operator.not_() function with examples in Python programming language.
Submitted by IncludeHelp, on April 14, 2020

operator.not_() Function

operator.not_() function is a library function of operator module, it is used to perform "NOT operation" on a given value and returns True if the given value is zero or any falsy value, False, otherwise.

Module:

    import operator

Syntax:

    operator.not_(x)

Parameter(s):

  • x – value on which NOT operation to be performed.

Return value:

The return type of this method is bool, it returns True if x is zero or any falsy value, False, otherwise.

Example:

# Python operator.not_() Function Example

import operator

print("operator.not_(True):", operator.not_(True))
print("operator.not_(False):", operator.not_(False))
print()

x = 1
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()

x = 10
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()

x = -10
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()

x = 0
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()

x = "Hello"
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()

x = ""
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()

Output:

operator.not_(True): False
operator.not_(False): True

x: 1
operator.not_(x): False

x: 10
operator.not_(x): False

x: -10
operator.not_(x): False

x: 0
operator.not_(x): True

x: Hello
operator.not_(x): False

x: 
operator.not_(x): True


Comments and Discussions!

Load comments ↻





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