Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the standard return value of a main function in Python?

I'm helping in a project of my course in the college and we have a script that depends on the return value of the main function of one of its modules (by main function, I mean the main()). But in that function, no value is returned: either the code has done successfully what it was supposed to do, or not. So, if there's no return statement in the function, what's the standard value to be returned if it reaches the end of the function?

like image 987
João H. L. Avatar asked Jan 28 '26 16:01

João H. L.


1 Answers

You've already made a false assumption from the start, which is that there is necessarily a main function at all. There isn't: Python doesn't need one, and doesn't call one automatically if it's there. Rather, all Python modules are executed from top to bottom; if the only thing at module level is a call to main(), then that is what is called, but otherwise it will not happen.

like image 111
Daniel Roseman Avatar answered Jan 31 '26 04:01

Daniel Roseman