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.

13th Aug 2021, 2:14 AM
Jenkins
2 Antworten
+ 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
13th Aug 2021, 2:18 AM
BootInk
BootInk - avatar
+ 1
True==not False False == not True
13th Aug 2021, 7:00 AM
Shadoff
Shadoff - avatar