Certified Associate in Python Programming (PCAP) — Question 17
A two-parameter lambda function raising its first parameter to the power of the second parameter should be declared as:
Answer options
- A. lambda (x, y) = x ** y
- B. lambda (x, y): x ** y
- C. def lambda (x, y): return x ** y
- D. lambda x, y: x ** y
Correct answer: D
Explanation
Option D is correct because it correctly uses the syntax for defining a lambda function in Python. Option A incorrectly uses '=' instead of ':', while Option B has an unnecessary parentheses around the parameters. Option C is not valid for lambda functions, as it uses 'def' instead of the lambda syntax.