Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

A developer writes a function that returns multiple values. How should they return these values?

⚠ Common exam trap

The PCEP exam often tests the distinction between returning multiple values as a tuple (comma-separated) versus returning a single container object like a list, tricking candidates who think lists are the only way to return multiple items.

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

✓

return a, b

In Python, a function can return multiple values by separating them with commas in the return statement. This automatically packs them into a tuple, which is then unpacked by the caller. Option A correctly uses `return a, b`, which returns a tuple `(a, b)`, allowing the caller to assign the results to separate variables.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    return a, b

    Why this is correct

    Returning a, b packs the two values into a single tuple, which the caller can unpack directly. Python has no multi-value return type, so the tuple is the mechanism that satisfies the requirement to return multiple values from one function.

  • ✗

    return a+b

    Why it's wrong here

    return a+b evaluates the sum and returns a single value, so the caller receives one object rather than the multiple values requested. It is tempting because arithmetic combination is a common reason to return a computed result, and it would be correct if the function's purpose were to total two numbers.

  • ✗

    return [a,b]

    Why it's wrong here

    Returning a list is valid Python, but the question asks how a function returns multiple values; the conventional mechanism is a tuple, which unpacks directly into separate variables. A list is tempting when the caller needs a mutable, homogeneous collection it can append to or iterate over later.

  • ✗

    return a; return b

    Why it's wrong here

    The first return statement ends the function immediately, so the second is unreachable and only a is ever returned. It is tempting because listing returns sequentially reads like emitting several results, and this pattern would be correct in a language where return does not terminate execution.

About these practice questions

Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.