Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should the main function and main() be placed at the start or the end of the program?

Tags:

python

I'm a beginner programmer and would like to know where to place my main function in python. I tried googling it but could not find any specific results. I don't think it really matters when you run the program but I was wondering if there was a proper format. Thanks.

like image 459
eukoloko Avatar asked Feb 20 '17 02:02

eukoloko


1 Answers

There's no established convention, but I think that code is easier to read if the main logic is near the top of the file. I typically will define a main at the top, and then call it from the very bottom.

like image 146
Bryan Oakley Avatar answered Oct 27 '22 11:10

Bryan Oakley