What is the purpose of the if __name__ == '__main__': block in Python?
Correct answer
D. Run code only when the file is executed directly, not imported
11 views
D. Run code only when the file is executed directly, not imported
11 views
The block prevents code from running when the module is imported elsewhere.
Asked in: Python Interview Basics
https://docs.python.org/3/tutorial/introduction.htmlNot sure why the answer is D? Ask here and get an explanation.