The
pass
statement does nothing. Sometimes we
need a placeholder to fill the syntactic requirements of a compound
statement. We use the
pass
statement to fill in the
required suite of statements.
The syntax is trivial.
Here's an example of using the pass statement.
if n%2 == 0:
pass # Ignore even values
else:
count += 1 # Count the odd values
Yes, technically, we can invert the logic in the if-clause. However,
sometimes it is more clear to provide the explicit "do nothing" than to
determine the inverse of the condition in the
if
statement.
As programs grow and evolve, having a
pass
statement can be a handy reminder of places where a program can be
expanded.