A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Return Values

College Depth 76 in the knowledge graph ☐ I know this ☆ Set as goal
735topics build on this
326prerequisites beneath it
See this on the map →
Defining and Calling FunctionsFunction Parameters and Argument Passing→→Error Handling and ExceptionsFunction Design and Contracts+2 more
return output functions None void

Core Idea

A return statement ends a function's execution and sends a value back to the caller. Functions that compute results should return those results rather than printing them, making them composable — the output of one function can be passed as input to another. A function without an explicit return statement returns None (or void), which is appropriate for functions called solely for their side effects. Understanding return values is key to writing reusable, testable functions.

How It's Best Learned

Write mathematical functions (e.g., area of a circle) that return a value, then use the returned value in larger expressions. Compare a version that prints vs. one that returns and observe which composes more naturally.

Common Misconceptions

Explainer

You already know that functions accept inputs through parameters. Return values are the other half of that contract: they let a function send a result back to the code that called it. When a function hits a `return` statement, two things happen simultaneously — the function stops executing, and the specified value is passed back to the caller. The caller can then store that value in a variable, pass it to another function, or use it in an expression. This is what makes functions composable: the output of one becomes the input of another, like snapping together building blocks.

The most important distinction to internalize early is returning versus printing. A `print` statement displays text on the screen for a human to read, but the program itself cannot use that displayed text for anything. A `return` statement sends a value back into the program's flow where other code can use it. Consider a function that calculates the area of a circle. If it prints the result, you can see the number, but you cannot use it to calculate the volume of a cylinder. If it returns the result, you can feed that value into a volume calculation, store it in a database, or compare it to a threshold — whatever the program needs. Printing is for humans; returning is for code.

A function that does not explicitly return a value still returns something — in Python it returns `None`, in Java a `void` function returns nothing at all. This is appropriate for functions whose purpose is a side effect: printing to the screen, writing to a file, or modifying a data structure in place. But functions that compute a result should almost always return it rather than printing it, because returning preserves the caller's freedom to decide what to do with the result.

One subtlety worth noting: a function can contain multiple `return` statements. Each one is an exit point — the first `return` that executes ends the function. This is useful for early returns that handle special cases. For example, a function that divides two numbers might return an error value immediately if the divisor is zero, rather than proceeding through the normal computation. Any code after a `return` statement in the same block will never execute, which is why your editor may warn you about "unreachable code." Understanding this control-flow behavior of `return` — that it is both a value-delivery mechanism and a function-exit mechanism — sets the foundation for recursion and error handling patterns you will encounter soon.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Conditional Statements → Defining and Calling Functions → Functions: Decomposing Problems → Function Parameters and Argument Passing → Return Values

Longest path: 77 steps · 326 total prerequisite topics

Prerequisites (2)

Leads To (4)