Jul-03-2022, 04:46 PM
EntOn() does not have a return, so by default it returns None. None does not equal True or False. None is false-ey, so it acts like False when used in an if statement, but it is not False (because they are different objects) and it does not equal False (because they are different types (None is class NoneType, False is class bool).
EntOn = False assigns EntOn to reference the object False. Now EntOn is False and cannot be used to call the function EntOn(). It is like you deleted the function from the program. It can no longer be used.
EntOn = False assigns EntOn to reference the object False. Now EntOn is False and cannot be used to call the function EntOn(). It is like you deleted the function from the program. It can no longer be used.
def EntOn(): pass print("EntOn", EntOn, type(EntOn), id(EntOn)) print("EntOn()", EntOn(), type(EntOn()), id(EntOn())) EntOn = False print("EntOn = False", EntOn, False, id(EntOn), id(False)) print("Call EntOn") EntOn()
Output:EntOn <function EntOn at 0x000001C713F108B0> <class 'function'> 1954544683184
EntOn() None <class 'NoneType'> 140735532587136
EntOn = False False False 140735532537712 140735532537712
Call EntOn
Traceback (most recent call last):
File "c:/Users/djhys/Documents/python/musings/junk.py", line 11, in <module>
EntOn()
TypeError: 'bool' object is not callable
From the program output you can see that EntOn starts out as a function and calling the function returns None. After assigning EntOn = False, EntOn is now the object False (They have the same object ID which means they are the same object). Now that EntOn is the same as False, calling EntOn() is the same as calling False().