Return Values

Also known as: return, function output

definition

The value that a function sends back to the code that called it, specified by the return statement. Return values make functions composable — you can chain functions together: double(triple(2)) = double(6) = 12.

💡 Intuition

A function is like a vending machine — you put in inputs (arguments) and get back an output (return value). The return value is what comes out.

Core Idea

Return values let functions communicate results back to their callers. A function without a return value just performs an action.

🔬 Example

def double(x): return x * 2. Then result = double(5) gives result = 10. The function returned 10.

🎯 Why It Matters

Return values make functions composable — you can chain functions together: double(triple(2)) = double(6) = 12.

⚠️ Common Confusion

Print and return are different. Print displays a value; return sends it back to the calling code for further use.

Related Concepts

Prerequisites

Next Steps

How Return Values Connects to Other Ideas

To understand return values, you should first be comfortable with function programming. Once you have a solid grasp of return values, you can move on to scope.

Go Deeper

Frequently Asked Questions

What is Return Values in CS Thinking?

The value that a function sends back to the code that called it, specified by the return statement.

Why is Return Values important?

Return values make functions composable — you can chain functions together: double(triple(2)) = double(6) = 12.

What do students usually get wrong about Return Values?

Print and return are different. Print displays a value; return sends it back to the calling code for further use.

What should I learn before Return Values?

Before studying Return Values, you should understand: function programming.