by chernevik · 14y ago · 0 comments
def f(L=None): L = L or []
These are the little assumptions that keep blowing off my feet. Thanks.
def f(x=None): x if x is not None else []But if this expression is a line in a larger function, and is intended to reset the value of argument x if no other value is passed in for it, does this really act as an assigment to x? Because I sort of read this expression as evaluating to some value -- the passed value for x, or a [] -- but does this assign that value to the argument x? Or must it be x = [expression]
def f(x=None): if x is None: x = [] L = [] if L is None else L