amyassin amyassin - 1 year ago 137
Python Question

How do I get the opposite (negation) of a Boolean in Python?

For the following sample:

def fuctionName(int, bool):
if int in range(...):
if bool == True:
return False
return True

Is there any way to skip the second if-statement? Just to tell the computer to return the opposite of the boolean

Answer Source

You can just use:

return not bool
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download