We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
You can refer to the discussion on: https://stackoverflow.com/questions/419163/what-does-if-name-main-do to get some idea.
Basically, name is a built-in variable which evaluates to the name of the current module. However, if a module is being run directly (as in myscript.py above), then name instead is set to the string "main". Thus, you can test whether your script is being run directly or being imported by something else by testing
if name == "main":
...
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Say "Hello, World!" With Python
You are viewing a single comment's thread. Return to all comments →
You can refer to the discussion on: https://stackoverflow.com/questions/419163/what-does-if-name-main-do to get some idea. Basically, name is a built-in variable which evaluates to the name of the current module. However, if a module is being run directly (as in myscript.py above), then name instead is set to the string "main". Thus, you can test whether your script is being run directly or being imported by something else by testing
if name == "main": ...