Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding "def main" and "overloading" in Python
    text
    copied!<p>I often see some code with</p> <pre><code>def main(A,B) some steps </code></pre> <p>described as an "overloading for the main function", after reading something more specific about Python I know that this is not true because:</p> <ul> <li>Python is a <em>loseless type</em> language</li> <li>a function/method in Python doesn't even know the type for a given parameter, nor python cares</li> </ul> <p>I'm also not sure if there is a real distinction between instances and "static methods" or "class methods", probably they are the same thing and the only difference is given by the use of decoratos, but this is probably related to my first approach to a functional language after spending so much time with C/C++ .</p> <p>Even more, in Python, the first indentation level is used as an entry point ( like main() in C/C++ ), so I don't get why you should define a main at an indentation level that is different from the really first one.</p> <p>The general idea that I have about Python's keywords is that the keywords have a special semantic value rather than a real defined syntax ( probably it's because the C++ is less "idiomatic" , I don't really know how explain that ), they are used as a placeholder for something and they give a special meaning to the section where they are applied. There also special variables like <code>__name__</code> that are there just to store special informations and nothing more.</p> <p>After all this small bits of information stored in my brain I still dont' get the real meaning of the first code example:</p> <ul> <li>what is special about the main() function ?</li> <li>what is the point of defining something like a "main" function if it's not real "main"</li> <li>how Python decide what function is the one to call if it's not typed ?</li> <li>there is a difference between how the interpreter reads <code>__init__.py</code> files and other files ?</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload