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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.