Ask Question
23 September, 11:55

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

+1
Answers (1)
  1. 23 September, 13:23
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers