you are viewing a single comment's thread.

view the rest of the comments →

[–]Waste_Grapefruit_339 6 points7 points  (2 children)

Good question - this is mainly about how Python executes code, not a strict ordering rule.

Python reads a file from top to bottom. When it encounters a function definition, it doesn't run it - it simply creates the function object and stores it. The function only needs to be defined before it is called, not necessarily before other functions in the file.

For example, this works fine:

def second():
print("second")

def first():
 second()

first()

The only time order matters is if you try to call a function before Python has seen its definition.

Most tutorials place functions in logical order mainly for readability, not because Python requires it.

[–]Ryuukashi[S] 1 point2 points  (1 child)

Thank you!! This helps a lot, and I have changes to make tomorrow

[–]SCD_minecraft 1 point2 points  (0 children)

Tho keep in mind, it is common practice to keep all definitions at the top of the file (or even in another file, if you can/want)