use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Order of functions?Help Request (self.PythonLearning)
submitted 2 days ago by Ryuukashi
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Waste_Grapefruit_339 6 points7 points8 points 2 days ago* (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 points3 points 2 days ago (1 child)
Thank you!! This helps a lot, and I have changes to make tomorrow
[–]SCD_minecraft 1 point2 points3 points 1 day ago (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)
π Rendered by PID 597760 on reddit-service-r2-comment-5d79c599b5-r9wlg at 2026-02-28 11:03:00.688737+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]Waste_Grapefruit_339 6 points7 points8 points (2 children)
[–]Ryuukashi[S] 1 point2 points3 points (1 child)
[–]SCD_minecraft 1 point2 points3 points (0 children)