python - Should I define functions inside or outside of main()? -
After reading the following, I think I understand the value of the simplest wrapping of scripts in a main () function I am / P>
Should I define the main functions inside or outside of me?
Is anyone right or wrong? What are the advantages and disadvantages of both methods?
I discourage defining the function inside main ()
, Especially if you have multiple files in Python script, do not do anything outside any function B
function defined inside the A
function A
It is seriously limiting its utility, for example functions can not be defined in main ()
, for example Defining the function inside
main ()
allows you to easily override other functions, and somewhere else which is the same name, but those are In instances where it is really useful, some are in the middle, and you should not do it as a normal practice. Overall, there are many reasons for defining outside tasks to define actions outside of main ()
, and if you are learning python, then definitely how to handle it .
Comments
Post a Comment