In Python, what is the difference between pass and return

if not instance:
    return # will pass be better or worse here?

Worse. It changes the logic. pass actually means: Do nothing. If you would replace return with pass here, the control flow would continue, changing the semantic of the code.

The purpose for pass is to create empty blocks, which is not possible otherwise with Python’s indentation scheme. For example, an empty function in C looks like this:

void foo()
{
}

In Python, this would be a syntax error:

def foo():

This is where pass comes handy:

def foo():
    pass

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)