Skip to content
Exercise · Q4

Q.With the help of an example show how can you return more than one value from a function.

Odisha ChseTextbookSubjective· 3mImportance★★★★★est
77% · 23/30 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Python functions return multiple values by returning them comma-separated — Python packs them into ONE tuple — and the caller either keeps the tuple or unpacks it into separate variables in one assignment.

Idea. A function's return statement can carry only one object — but that object can be a tuple, and Python makes this seamless: writing return x, y, z automatically packs the three values into the tuple (x, y, z). On the calling side, tuple unpacking — a, b, c = f() — splits it back into individual variables. This is how Python idiomatically "returns more than one value".

Example — one function computing three results:

def arithmetic(a, b):
    """Return the sum, difference and product of a and b."""
    total = a + b
    diff = a - b
    prod = a * b
    return total, diff, prod       # tuple packing: (total, diff, prod)

# Way 1: receive the whole tuple
result = arithmetic(10, 4)
print(result)
print(type(result))

# Way 2: unpack into separate variables
s, d, p = arithmetic(10, 4)
print("Sum =", s)
print("Difference =", d)
print("Product =", p)

Output

(14, 6, 40)
<class 'tuple'>
Sum = 14
Difference = 6
Product = 40

Key lines:

  • return total, diff, prod — the commas build a tuple; parentheses are optional here. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.