0
Help me understand the meaning of the *not* keyword
def func(num): if num %2 == 0: return True else: return False print(not func(5)) The output I get is True. My question is just because itâs not 5 why doesnât it mean it automatically is a 2 for the function to accept and return it as True. Can someone please explain the reason for this? An analogy would be: just because my son didnât tell the whole truth doesnât necessarily mean that he lied.
2 Answers
+ 1
If this is in the python language (which is certainly looks to be), the not statement simply inverts, or negates, the state of a boolean. For example, if the value of a boolean variable or expression is true, it will result in false. If true, false is the result.
For example:
(True) and (not(False)) -> (True) and (True) -> true
+ 1
True==not False
False == not True