For the following sample:
def fuctionName(int, bool):
if int in range(...):
if bool == True:
return False
else:
return True
Is there any way to skip the second if-statement? Just to tell the computer to return the opposite of the boolean bool?
To negate a boolean, you can use the
notoperator:Or in your case, the
if/returnblocks can be replaced by:Be sure to note the operator precedence rules, and the negated
isandinoperators:a is not banda not in b.