r/programming • • Oct 21 '22

5 Uses of Lambda Functions in Python

https://medium.com/p/97c7c1a87244
0 Upvotes

1 comment sorted by

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):

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.