Search code examples
pythonpython-2.7commentsno-op

Python NOOP replacement


Often I need to temporary comment some code, but there are situations like the following where commenting a single line of code will get a syntax error

if state == False:
    print "Here I'm not good do stuff"
else:
#    print "I am good here but stuff might be needed to implement"

Is there something that might act as an NOOP to keep this syntax correct?


Solution

  • The operation you're looking for is pass. So in your example it would look like this:

    if state == False:
        print "Here I'm not good do stuff"
    else:
        pass
    #    print "I am good here but stuff might be needed to implement"
    

    You can read more about it here: http://docs.python.org/py3k/reference/simple_stmts.html#pass