Proper Pass Use


I just finished the classes intro lesson but I am still confused as to when it is necessary to include pass when creating a class…sometimes the exercises ran fine without it and sometimes not.

Could anyone please explain? Thanks in advance!

Edit: An interesting SO answer discussing some potential uses-

By definition pass doesn’t really do anything. The only time you’d use it is when you have a code block required but you don’t want to include any code-

if expression:
# without pass (or anything else) we get syntax errors
class:   # <-- on its own, this is a syntax error

Actual use cases are more limited as you’d almost include code behind each of these statements, perhaps a web search will net you a few best practices. The only one that I recall offhand is creating unique exceptions without altering the behaviour of the base class, not particularly useful but there you go :laughing:.

class NoodlingError(Exception):

Is there a specific lesson that caused trouble, is there a link?

1 Like

Thanks for this link and explanation! There was many exercises in the introduction to classes lesson that included pass, even when there was executable code in the class block - however, I have a feeling that this is because the lesson begins before the code is implemented and that they just did not bother to remove the pass afterward.