Make function definition in a python file order independent [duplicate]

All functions must be defined before any are used.

However, the functions can be defined in any order, as long as all are defined before any executable code uses a function.

You don’t need “forward declaration” because all declarations are completely independent of each other. As long as all declarations come before all executable code.

Are you having a problem? If so, please post the code that doesn’t work.


In your example, print_something() is out of place.

The rule: All functions must be defined before any code that does real work

Therefore, put all the statements that do work last.

Leave a Comment