Today we’ll be talking about the pass statement.
The pass statement can be used when a statement is required syntactically but we don’t want to deliver it. The result of the pass statement is null – nothing happens. We often use it in code stubs that are to be filled in later on.
Here’s an example. In the for loop there is supposed to be some loop body, i.e. some code executed inside the loop. Let’s see what happens if we don’t deliver any code:
>>> for i in range(5):
...
File "<stdin>", line 2
^
SyntaxError: unexpected EOF while parsing
>>>
We’re getting an error telling us that something that was expected was not found. Suppose we want to use this for loop, but we are going to think about its implementation only later. So, in order to get rid of the error for the time being we can use pass:
>>> for i in range(5):
... pass
...
>>>
This code doesn’t do anything, but at least it doesn’t raise an error. You can also use the pass statement in function and class definitions.