Return Values
12 minutes read
Beginner friendly
Includes practice
👋 Hi! In this short lesson you’ll learn what a return value is, why it matters, and how to use it effectively in your own functions.
By the end you’ll be able to write small, reusable “data factories” that hand back results you can save, combine, or test.
Runtic's Learning Tips
Think of
returnas a "hand back" — not just a display.Reusing output makes code more flexible and predictable.
Practicing small function returns improves testability.
Big-picture goal
When we call a function, we often want an answer back—not just text shown on screen.
A return value is that answer.
Real-world analogy:
- A printer (
print) spits ink onto paper, and you see it, but can’t re-use it. - A vending machine (
return) drops a snack into your hand—you can keep it, pass it around, or store it later.
What actually happens?
A function:
- Does some work
- Hits the keyword
return - Hands back one value to the caller
- Immediately stops—the rest is skipped
Interactive Code EditorExample Code
pythonThis won’t affect your saved progress.
return vs. print
returngives data out — reusable and storable.printonly displays output — not reusable.- After
return, nothing further in the function runs.
The default return (None)
If a function doesn’t include a return statement, Python quietly returns the special object None.
Interactive Code EditorExample Code
pythonThis won’t affect your saved progress.
Many beginners wonder: “Why is my variable None?”
The answer: you printed something, but you didn’t return anything!
Multiple return paths (exit early)
You can exit early using return, before the entire function finishes.
Interactive Code EditorExample Code
pythonThis won’t affect your saved progress.
Try these practical tasks below. They're great for building retention. Edit the code to fix or complete it.
Practice: Fix the Function
Practice Challenge
Define a function called rectangle_area(width,height)that calculates the area of a rectangle. Instead of printing the area, return it using return.Then call the function with 3and 4,store the result in area,and print it to verify the result.
Use return instead of print to send back the computed area.
Practice: Convert Celsius → Fahrenheit
Practice Challenge
Write a function called c_to_f(celsius)that converts a temperature from Celsius to Fahrenheit using the formula F = C * 9/5 + 32. Then call the function with 37 and store the result in f. Finally, print the resultto verify.
Use the formula F = C * 9/5 + 32. Input is 37°C.
Quick Practice
2 minutesChoose the best answers to understand return behavior.
Which statement about `return` is TRUE?
Quick Summary
print()displays output;returnsends back data to the callerSkipping
returngives backNoneautomaticallyReturning
Nonecan signal failure or special case (e.g. divide by zero)
Keep Going
Still tripping on when to return? That’s OK! These patterns take a few rounds to feel automatic. Every attempt builds stronger neural links—mistakes are just trail markers for learning.
- You learned what
returndoes and how it differs fromprint() - You explored
Noneas the default return when noreturnis written - You used multiple
returnpaths to handle branching logic cleanly - You practiced writing functions that give back reusable data
AI Tutor
Solve first — tutor's here to guide.
Runtric might be wrong. Think critically.