Skip to content
Skip to resources
peazit

What do you want to understand today?

PEAZIT Aha card

Functions: return sends a value to the caller

Go straight to resources ↓

def names a reusable procedure. A call gives a parameter its argument value. return ends that call and passes back the result; print displays something but does not return that displayed value.

Functions: return sends a value to the caller
ObservationWhat it means
def double(x): return 2*xprocedure definition
double(4)returns 8

One worked example

  1. def add_one(x): return x + 1x is the parameter.
  2. y = add_one(5)Argument 5 is substituted for x.
  3. y = 6The result 5 + 1 is assigned to y.

Watch out: Reaching the end of a function or using bare return produces None. print is not a substitute for returning the result.

Goal, prerequisites and card origin

What you will learn: Substitute an argument and use the returned value.

What you need first: Variables and simple expressions.

An original PEAZIT working card. Independent expert review and effectiveness testing have not yet taken place. · v1

Reference for the underlying principle ↗
Show connections

def names a reusable procedure. A call gives a parameter its argument value. return ends that call and passes back the result; print displays something but does not return that displayed value.

Other options for this topic

Catalogue

Find your own way. Resources open directly on their authors’ websites. Order reflects search relevance, not a teaching-quality rating.

47,636 resources to explore

15 independent sources

3 resource languages

EXPLORE / EN

Where will curiosity take you?

Start with a subject. Then find your way.

All topics
peazit

Everyone learns differently. Find your way.

Saved

For your next aha.

Your saved links stay in this browser.