PCAP-31-03 practice question 13 of 25

Which of the following lambda function definitions are correct? (Select two answers)

Full set: 147 questions
Answer options
A: lambda X : None Correct answer
B: lambda : 3,1415 Correct answer
C: lambda x : def fun(x): return x
D: lambda lambda: lambda * lambda
Correct Answer:
A. lambda X : None; B. lambda : 3,1415
Explanation

A lambda requires only a parameter list (which may be empty) and a single expression.
A. One parameter X, expression None – valid.
B. No parameters, expression 3,1415 – the comma creates a tuple (3, 1415) – valid.

Why Incorrect

C. Lambda body must be an expression, not the statement “def fun(x): …”.
D. Identifier “lambda” is a reserved keyword; it cannot be used as a parameter name.

References

1. Python 3.11 Language Reference, “Lambdas” (§6.23).

2. University of Cambridge ACS “Python: Functions & Lambdas” handout, §2.

Scroll to Top