Negate a Boolean Value in Python

How to get the opposite of a boolean in python?

 

A boolean(either True or False) is a primitive data type whose values are either True or False. The negation of a boolean like as true or false is the opposite of its current value.

USE THE not OPERATOR TO NEGATE A BOOLEAN VALUE

The not keyword returns the logical negation of a boolean value(either True or False). Invoke the not keyword by placing it in front of a boolean(either True or False) expression. If an expression evaluates to True, placing not in front of it will return False, and vice-versa.

Example 1:
 

expression = True

print(expression)
//RESULTS
True
print (not expression)
//RESULTS
False

 

USE THE operator.not_() FUNCTION TO NEGATE A BOOLEAN VALUE

Calling operator.not_(boolean) either True or False with a boolean value boolean to negate it. This method is used if a function is required instead of an operator, like in higher-order functions such as map or filter.
 

print(operator.not_(True))

//RESULTS
False
print(operator.not_(False))

//RESULTS
True

booleans = [True, False, True, False, True]
negation_iterator = map(operator.not_, booleans)

print(list(negation_iterator))
//RESULTS
[False, True, False, True, False]

 

I hope you get an idea about Python not: If Not True.


#py  #python 

Negate a Boolean Value in Python
1.00 GEEK