5

Is there a way to code:

def fn():
    return None

as a lambda, in Python?

3 Answers 3

12

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You have to do this:

fn = lambda: None

Comments

0

to be sure that works even with positional and kewyword arguments:

fn = lambda *args, **kwargs: None

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.