Search code examples
pythonif-statementsyntaxsemantics

Proper Python Syntax and Semantics: if, else, pass


Is there a preferred/proper style?

This:

def fx(Boolean):
    if Boolean:
        # Do stuff.
    else:
        pass

Or this:

def fx(Boolean):
    if Boolean:
        # Do stuff.

Is it preferred/proper to include else: pass if you don't want anything to happen?
I've read PEP 8 - Style Guide for Python Code and did not find anything concerning my question.


Solution

  • You should never include else: pass. It's superfluous. Just omit the else; it's intentionally an optional keyword.