Rez Rez - 2 months ago 6x
Python Question

Python: pass statement in lambda form

A Python newbie question, why is this syntax invalid:

lambda: pass
, while this:
def f(): pass
is correct?

Thanks for your insight.


That is an error because after the colon you have to put the return value, so:

lambda: pass

is equal to:

def f():
   return pass

that indeed makes no sense and produces a SyntaxError as well.