Robotics & Artificial Intelligence

What is the purpose of the 'pass' statement in Python?

  1. It terminates a loop when a condition is met
  2. It skips the current iteration of a loop
  3. It serves as a placeholder, allowing code to be syntactically correct while leaving the body empty
  4. It repeats the current iteration in a loop

Python Control Flow

3 Likes

Answer

It serves as a placeholder, allowing code to be syntactically correct while leaving the body empty

Reason — The pass is a keyword and a null statement. It is used as a placeholder when a loop, function, or conditional statement is required syntactically but no action needs to be performed. Unlike comments, the pass statement is not ignored by the interpreter and helps keep the code syntactically correct while the body is left empty.

Answered By

2 Likes


Related Questions