Ask Question

When a Python script is running as a standalone program, what will the __name__ variable be set to?

+1
Answers (1)
  1. 2 July, 17:40
    0
    When a Python script is running as a standalone program, the __name__ variable will be set to __main__.

    Explanation:

    Python does not have main () function like some other programming language. So, when a command is given the interpreter to execute a python program, the code that is indented least (that is level 0) is executed first.

    However, before doing that, it will define a few special variables. __name__ is one such special variable. If the source file is executed as the main program, the interpreter sets the __name__ variable to have a value "__main__". If this file is being imported from another module, __name__ will be set to the module's name.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “When a Python script is running as a standalone program, what will the __name__ variable be set to? ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers