PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
A developer is using a lambda function that takes two arguments and returns their sum. Which of the following lambda expressions is correct?
⚠ Common exam trap
Python Institute often tests the misconception that lambda requires an explicit `return` statement, leading candidates to choose Option C, but in reality the expression after the colon is automatically returned.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
lambda a, b: a + b
Option A correctly defines a lambda function that takes two arguments and returns their sum. Option B is a valid lambda but returns the difference (a - b), not the sum, so it does not meet the requirement. Option C is incorrect because lambda expressions cannot include a `return` statement; the result is implicitly returned. Option D uses `def` to define a named function, not a lambda.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
lambda a, b: a + b
Why this is correct
Python lambda syntax places parameters before the colon and the single return expression after it, with no return keyword. Writing lambda a, b: a + b correctly declares two parameters and returns their sum, matching the two-argument addition requirement exactly.
- ✗
lambda a, b: a - b
Why it's wrong here
The subtraction operator returns a difference, not a sum, so the expression computes the wrong result for the stated requirement. It is tempting because the syntax is a valid two-argument lambda; it would be correct only if the function were specified to subtract the second argument from the first.
- ✗
lambda a, b: return a + b
Why it's wrong here
A lambda body is a single expression, so including the return keyword is a syntax error. It is tempting because the parameters and the a + b operation are correct; the valid form would be lambda a, b: a + b, which returns the sum implicitly without return.
- ✗
def add(a, b): return a + b
Why it's wrong here
A def statement defines a named function, not a lambda expression, so it fails the requirement to use lambda syntax. It is tempting because the body correctly returns a + b and the parameters match; it would be the right approach when a reusable, named function is wanted instead of an anonymous one.
Quick reference
Cloud Service Model Comparison
| Model | You Manage | Provider Manages | Examples |
|---|---|---|---|
| IaaS | OS, runtime, apps, data | Hardware, hypervisor, networking | EC2, Azure VMs, GCP Compute Engine |
| PaaS | Apps and data | OS, runtime, middleware, hardware | Elastic Beanstalk, Azure App Service |
| SaaS | Data and settings only | Everything else | Microsoft 365, Salesforce, Workday |
| FaaS / Serverless | Function code only | Infra, scaling, runtime | Lambda, Azure Functions, Cloud Run |
| CaaS | Containers and apps | Kubernetes, OS, hardware | EKS, AKS, GKE |
Go deeper
Related to this question
About these practice questions
One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.