Best practice for setting the default value of a parameter that’s supposed to be a list in Python?

Use None as a default value:

def func(items=None):
    if items is None:
        items = []
    print items

The problem with a mutable default argument is that it will be shared between all invocations of the function — see the “important warning” in the relevant section of the Python tutorial.

Leave a Comment

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