PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 56


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

Show Answer
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

2 comments
Sign in to comment
ciccio_benzinaOption: C
Sep 5, 2022

not = but ==

baimus
May 1, 2023

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

macxszOption: C
May 3, 2022

C. __main__