Ask Question
21 May, 05:25

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

+2
Answers (1)
  1. 21 May, 06:14
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers