3 ms·
In Python, I believe function declarations work dynamically, just as variable declarations do. When I'm writing Python scripts, I usually have some code at the
by gengkev 10y ago
In Python, I believe function declarations work dynamically, just as variable declarations do. When I'm writing Python scripts, I usually have some code at the global level that calls functions, which must then be above that code. (This is in contrast to a compiled language like C, or JavaScript, which hoists function and var declarations.)
This can be worked around by stuffing everything into a main method and putting if __name__ == '__main__': main() at the bottom of the file (which I usually do anyway). But the mere requirement that you must remember to do so, just as you must remember to forward-declare functions in C, is still an incentive to work from the bottom of the file upwards.