Quick Tip: Python's noop Equivalent

Nov 30, 2007

Python can’t deal with empty code blocks, which may arise if you want to stub out a block but leave the implementation for later. If you have one in your code, the interpreter will give the following error:

  File "foo.py", line 1
    if (foo == bar):
IndentationError: expected an indented block

In this case, you can use the pass operator which will do nothing but take up a line, resulting in the following code:

if (foo == bar):
    pass #TODO
    print "nothing to do!"