Which is more preferable to use: lambda functions or nested functions (“def”)?

StackOverflow

I mostly use lambda functions but sometimes use nested functions that seem to provide the same behavior.

Here are some trivial examples where they functionally do the same thing if either were found within another function:

Lambda function

>>> a = lambda x : 1 + x
>>> a(5)
6

Nested function

>>> def b(x): return 1 + x

>>> b(5)
6

Are there advantages to using one over the other? (Performance? Readability? Limitations? Consistency? etc.)

Does it even matter? If it doesn"t then does that violate the Pythonic principle:

There should be one-- and preferably only one --obvious way to do it..





Tutorials