When you run a Python module with python fibo.py <arguments> the code in the module will be executed, just as if you imported it, but with the __name__ set to "__main__". a command-line interface for a package. How to Create a Basic Project using MVT in Django ? Example 2: Polymorphic len () function Before that, its very necessary to understand that the Python interpreter sets __name__ depending on the way how the code is executed. There is also a conditional (or if) statement that checks the value of __name__ and compares it to the string "__main__". Any code that is not protected by that guard will be executed upon execution or importing of the module. A 101 Guide On The Least Squares Regression Method, Python Career Opportunities: Your Career Guide To Python Programming, Top Python developer Skills you need to know, Learn How To Make A Resume For A Python Developer. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. status code 0, indicating success: Note that importing __main__ doesnt cause any issues with unintentionally On the other hand, the Python interpreter executes scripts starting at the top of the file, and there is no specific function that Python automatically executes. Functions in Python Functions in Python Python Function is a piece of code or any logic that performs a specific operation. Note that if you import the module again without quitting Python, there will be no output. When this is done, pip inserts the function call into a template script, where the return value of main is passed into sys.exit () . This happened because the variable __name__ has the value "__main__" when the Python interpreter executes the file as a script, so the conditional statement evaluated to True. You will learn about four best practices to make sure that your code can serve a dual purpose: Remember that the Python interpreter executes all the code in a module when it imports the module. How about saving the world? __name__ takes on different values depending on how you executed your Python file. Here is an example module that consumes the __main__ namespace: Example usage of this module could be as follows: Now, if we started our program, the result would look like this: The exit code of the program would be 1, indicating an error.