Exam PCAP All QuestionsBrowse all questions from this exam
Question 56

What should you put instead of XXX to print out the module name?

    Correct Answer: C

    To print out the module name in Python, you should use the special variable __name__. When a Python file is run directly, the __name__ variable is set to '__main__'. Therefore, to check if the module is being run directly, you compare __name__ to '__main__'. If they are not equal, it means the module is being imported elsewhere, and you print the module name using __name__. So the correct replacement for XXX is '__main__'.

Discussion
ciccio_benzinaOption: C

not = but ==

baimus

They have capitalised the If and put a space between ! and =, so I think they mean if __name__ !="__main__"

macxszOption: C

C. __main__