Why is the block if __name__ == “__main__”: commonly used in a Python module?
Correct answer A. So the code inside runs when the file is executed directly but not when it is imported
Explanation
When a file runs as a script, its __name__ is "__main__"; when imported, __name__ is the module name. Guarding script code with this test lets the file be reused as a module without running its tests or command-line logic on import. Python has no required main() entry point.
Answer checked How we write and check questions
Discussion