If I have a python function which can be expressed with one line, which one of the following options is generally considered best for readability and general best practices? Or is there another option that’s better? Option 2 seems far and away the best to me, but I’m a beginner, so I don’t want to assume anything. I’ve tried searching PEP8, Stack Overflow, and a blog or two, but I haven’t been able to find anything explicit for python.
def f(x): return do_something(x)
def f(x):
return do_something(x)
f = lambda x: do_something(x)
Lucas Grenier is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.