Skip to content
ComputerCS
Start learning

Python Programming · Lesson 2.5.1.2–2.5.1.3

Parameters, Arguments & Return

Send data in with positional and keyword arguments, give parameters defaults, and send results out with return — not print.

01

Learning objectives

  • Distinguish parameters (in the def) from arguments (in the call).
  • Call functions with positional and keyword arguments, mixed correctly.
  • Write functions with default parameter values and predict calls that omit them.
  • Explain the difference between return and print using a function's result.
  • Trace chained calls where one call's result feeds into another.
02

Lesson notes

Vocabulary first, because the exam tests it: parameters are the placeholder names in the def line; arguments are the actual values written in the call. In def bill(item, qty): and the call bill('pen', 3), item and qty are parameters while 'pen' and 3 are arguments. Positional arguments are matched purely by order: first to first, second to second, third to third.

Keyword arguments skip the order worry: bill(qty=3, item='pen') names each value, so the call reads clearly and cannot be mismatched. You may mix styles — positional first, then keyword — but never a positional argument after a keyword one, which is a SyntaxError. Defaults move flexibility into the definition: def bill(item, qty=1, price=100) lets the call bill('copy') work, filling the omitted parameters with their default values.

return ends the function and hands a value to the caller. That value is then ordinary data: store it, print it, feed it into the next call — double(double(5)) chains naturally. Returning a tuple even delivers two answers at once: return low, high. A function may contain several return statements, one per branch, but each single call executes exactly one of them and then stops.

The return-versus-print distinction is the most failed exam item in this chapter. print writes text to the screen for humans; return gives a value to the rest of the program. A function that only prints computes a result and then throws it away — its caller receives None, so total = printed_version(nums) + 1 crashes with TypeError. The working rule: functions return values; the main code does the printing.

Board tip: when asked for the output of a program, trace arguments into parameters one line at a time, then follow the return value back to the call site. Watch for calls that omit middle arguments (defaults fill them) and for expressions inside calls — f(a + 1, b * 2) evaluates both expressions fully before the function even starts running.

03

Worked code examples

Defaults and keyword arguments

Positional arguments fill item, qty and price in order; a keyword argument skips straight to price; omitted parameters take their defaults, so qty stays 1.

def bill(item, qty=1, price=100):
    return item, qty * price

print(bill("pen", 3, 20))
print(bill("bag", price=450))
print(bill("copy"))
Output
('pen', 60)
('bag', 450)
('copy', 100)

Return values chain into new calls

first is 10; then double(10) is 20 and double(3) is 6, so second is 26. Returned values behave like any other numbers.

def double(n):
    return n * 2

first = double(5)
second = double(first) + double(3)
print(first, second)
Output
10 26

Keyword order does not matter

Positional matching uses order; keyword matching uses names, so the second call is valid despite being written in reverse.

def intro(name, city):
    return name + " lives in " + city

print(intro("Sara", "Lahore"))
print(intro(city="Multan", name="Umar"))
Output
Sara lives in Lahore
Umar lives in Multan
04

Key terminology

parameter

A placeholder name in the def line, filled by an argument at call time.

argument

An actual value written in a function call.

keyword argument

An argument passed by name, like price=450, matched to the parameter of that name.

default value

A value written in the def line that is used whenever the call omits that argument.

return statement

Ends the function and hands a value back to the caller.

05

Common misconceptions

Common mistake

print(x) and return x do the same job inside a function.

Correct understanding

print shows x on the screen; return hands x back to the caller for further use. Only return lets the caller compute with the value.

Common mistake

Keyword arguments must be written in the same order as the parameters.

Correct understanding

Keywords are matched by name, so their order is free — but positional arguments must never follow keyword arguments in the same call.

Common mistake

Once a parameter has a default, the function still demands it at every call.

Correct understanding

A defaulted parameter may always be omitted; the default is used automatically.

06

Check your understanding

1. def f(a, b=2): return a * b — what is f(3)?

2. Which call is INVALID for def order(item, qty, price)?

3. g prints its total instead of returning it. What is x after x = g([1, 2, 3])?

NERDLYY · FEEDBACK

Help shape Nerdlyy

Your feedback goes directly to the team. We read every submission.

No reply needed — you can send feedback without sharing contact details.