Junior — Middle
When does the creation of a function instance occur in Python?
sobes.tech AI
Answer from AI
In Python, an instance of a function is created in memory at the moment the function is defined, i.e., when the interpreter reaches the line with the 'def' keyword. At this point, a function object is created and associated with the name in the current scope.
For example:
def foo(): pass
When the interpreter executes this line, it creates a function object 'foo'. Before this, the function does not exist as an object in memory.