Reputation: 4117
Is there a way to code:
def fn():
return None
as a lambda, in Python?
Upvotes: 5
Views: 598
Reputation: 350
to be sure that works even with positional and kewyword arguments:
fn = lambda *args, **kwargs: None
Upvotes: 0
Reputation: 157414
Yes, the argument list can be omitted:
fn = lambda: None
The production from 5.12. Lambdas is:
lambda_form ::= "lambda" [parameter_list]: expression
The square brackets around parameter_list
indicate an optional element.
Upvotes: 12