[Solved] How function is getting called without defining in python [closed]


Make sure your code is exactly as it is now in the question (including the edit by @Haidro)

The code, as you pasted it in the question, suggests your indentation was something like this:

def my_function():
    '''
    docstring
    '''
code_intended_for_my_function()

#my_function()

This would cause code_intended_for_my_function to be executed. This is “valid” because the docstring makes the definition for my_fuction valid (it just does nothing), then immediately executes code_intended_for_my_function. To test this, in the code you have, remove the docstring and check if you get an IndentationError, or just copy the code as it is currently from the question and see if it works as you expect.

5

solved How function is getting called without defining in python [closed]