What does if __name__ == ”__main__” do in Python?
When and how a main method is executed in Python
If you are new to Python, you might have noticed that it is possible to run a Python script with or without a main method. And the notation used in Python to define one (i.e. if __name__ == ‘__main__'
) is definitely not self-explanatory especially for new comers.
When and how a main method is executed in Python
If you are new to Python, you might have noticed that it is possible to run a Python script with or without a main method. And the notation used in Python to define one (i.e. if __name__ == ‘__main__'
) is definitely not self-explanatory especially for new comers.