R

Rati Dubey • 8.55K Points
Tutor III

Q. Which statement is used to define a block of code that runs only when the program is executed directly, not when imported?

  • (A) if __main__ == '__name__':
  • (B) if __name__ == '__main__':
  • (C) main():
  • (D) run()
  • Correct Answer - Option(B)
  • Views: 11
  • Filed under category Python

Explanation by: Rati Dubey
The `if __name__ == '__main__':` block ensures the code runs only when the file is executed directly.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.


Question analytics