1. Concept library
  2. Python Foundations
  3. Module 3: Functions

Concept

Parameters and return values

A function takes inputs through its parameters and hands a result back with return. Code that returns a value is easier to test and reuse than code that only prints.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain the difference between returning a value and printing it
  2. Write a function that takes parameters and returns a result the caller can reuse
  3. Predict what a caller gets from a function with no return statement

In practice

A few lines that show Parameters and return values doing its job.

Python
def area(width, height):
    return width * height

kitchen = area(4, 3)
print(kitchen)              # 12

def greet(name):
    print("Hello", name)

result = greet("Ada")       # prints, but result is None

The common mistake

Watch for

Printing inside a function instead of returning. The caller gets None back, so the value cannot be stored, compared or passed on.

What to know first

Your roadmap puts these before Parameters and return values, unless you already know them.

How it stays learned

Once a session shows you understand Parameters and return values, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Parameters and return values.