Practice mode Python

A file containing only the following line is run directly as a script. What is the output? print(__name__)

Correct answer C. __main__

Explanation

When a file is run directly as a script, the interpreter sets its module-level __name__ to the string "__main__". When the same file is imported, __name__ holds the module name instead. This is what makes the if __name__ == "__main__": idiom work.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.