Chapter 3
Python Basics 3 – Functions and Reuse

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 return as 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:

  1. Does some work
  2. Hits the keyword return
  3. Hands back one value to the caller
  4. Immediately stops—the rest is skipped

Example Code

Interactive Code Editor
python

This won’t affect your saved progress.

return vs. print

  • return gives data out — reusable and storable.
  • print only 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.

Example Code

Interactive Code Editor
python

This 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.

Example Code

Interactive Code Editor
python

This 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

Interactive Code Editor
📝 Your Task:

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.

python

Use return instead of print to send back the computed area.

Practice: Convert Celsius → Fahrenheit

Practice Challenge

Interactive Code Editor
📝 Your Task:

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.

python

Use the formula F = C * 9/5 + 32. Input is 37°C.

Quick Practice

2 minutes

Choose the best answers to understand return behavior.

Which statement about `return` is TRUE?

Quick Summary

  • print() displays output; return sends back data to the caller

  • Skipping return gives back None automatically

  • Returning None can 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.

Lesson Complete!
100%
Progress
What You've Learned:
  • You learned what return does and how it differs from print()
  • You explored None as the default return when no return is written
  • You used multiple return paths to handle branching logic cleanly
  • You practiced writing functions that give back reusable data

Sign in to track your progress

Chapter Progress

0 secs

AI Tutor

Powered by Runtric

Solve first — tutor's here to guide.

Runtric might be wrong. Think critically.