Rez Rez - 1 year ago 82
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download