PEP8 discourages naming lambdas and for good reasons. Using named functions is the better choice, it's not just a matter of style, besides allowing you to add multiple lines you can have docstrings, type hints and better tracebacks, and for single statements they can be one liners too (although I don't like it personally):
def add_ten(x): return x + 10
It's hard to justify giving up so many features just to save a line or a few characters.
5
u/RiverRoll Oct 21 '22 edited Oct 21 '22
PEP8 discourages naming lambdas and for good reasons. Using named functions is the better choice, it's not just a matter of style, besides allowing you to add multiple lines you can have docstrings, type hints and better tracebacks, and for single statements they can be one liners too (although I don't like it personally):
It's hard to justify giving up so many features just to save a line or a few characters.