🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Modules and Libraries: all 14 questions

Quiz: Modules and Libraries · Question 3 of 14

What is the purpose of if name == "main":?

What is the purpose of if __name__ == "__main__":?

  1. A.To make the program faster
  2. B.To run code only when the file is executed directly, not when imported
  3. C.To declare the main function
  4. D.It is required in every file
Answer & explanation

Correct answer: To run code only when the file is executed directly, not when imported

When a file is imported, name is the module name, so that block is skipped.

Can you get the rest right without peeking?

Take the timed Quiz: Modules and Libraries quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →