aerial view of zigzag road on mountain
Photo by Johannes Hofmann on Unsplash

If you are implementing a new class, but do not have time now, or simply want to postpone it for later, then you can use the pass statement.

I have seen it being used all over the place, and I think it is a good idea to use it when you are writing a class that does not have any bodies of any methods, or when you are implementing a class that is not yet complete.

You can use it to do test-driven development when you initially write a failing test that calls a method that is not implemented yet, which you can then implement and fix the failing test.

Another scenario when I saw it being used was in coding assignments that are part of homework.

It is relatively straightforward to use it. You can write the name of a method and then underneath it, simply write _pass_ which tells Python interpreter to not throw any errors as you can see in the following example:


In the above example, we have a method called _get_user_ that does not have a body of the method. We can use the pass statement to tell Python interpreter to not throw any errors.

Do not forget to replace pass method with the body of the actual method. If you leave it there just because you do not want to have the Python interpreter yell at you, then you can remove it, since it can also be a source of potential bugs. Your colleagues or even you may get the feeling from its presence that it is supposed to do something and may not take the time to see that this is actually not the case.


That’s it for this article.

I hope you find it useful.