0Pricing
Learn AI with Python · Lesson

Return Values

Discover how to use return values to make functions more versatile.

Return Values is a free Learn AI with Python lesson on CoddyKit — lesson 2 of 5. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 5 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

Introduction to Return Values

Return values allow functions to send data back to the part of the program that called them. This makes functions more versatile and reusable.

In this lesson, you will learn how to use return values effectively in Python functions.

Return Values — illustration 1

2

What is a Return Value?

A return value is the output of a function. You can use the return keyword to send data back to the caller.

For example:

# Function with a return value
def add(a, b):
    return a + b

result = add(3, 5)
print(result)

3

4

Returning a Single Value

A function can return a single value using the return keyword:

# Returning a single value
def square(x):
    return x * x

result = square(4)
print(result)

5

Returning Multiple Values

You can return multiple values from a function as a tuple:

# Returning multiple values
def min_and_max(numbers):
    return min(numbers), max(numbers)

nums = [3, 5, 7, 2, 8]
minimum, maximum = min_and_max(nums)
print(minimum, maximum)

6

Using Return Values

Return values can be stored in variables or used directly in expressions:

# Using return values
def double(x):
    return x * 2

print(double(4) + double(5))

7

Returning None

If a function doesn’t have a return statement, it automatically returns None:

# Function returning None
def greet():
    print("Hello!")

result = greet()
print(result)

8

Practical Example

Here’s an example of a function that calculates the area of a rectangle:

# Practical example
def area_of_rectangle(length, width):
    return length * width

print(area_of_rectangle(5, 10))

9

def multiply(a, b):
    return a * b

result = multiply(3, 4)
print(result)

10

Common Mistakes with Return Values

Here are some common mistakes to avoid:

  • Forgetting to use the return keyword in a function.
  • Trying to use a function’s output without storing or using its return value.
  • Returning incompatible types for expected use cases.

11

What Did We Learn?

In this lesson, you learned:

  • What return values are and how to use them.
  • How to return single or multiple values from a function.
  • Practical applications of return values in Python.

Great job! Let’s move to the next lesson.

Return Values — illustration 11

Frequently asked questions

Is the “Return Values” lesson free?

Yes — the full text of “Return Values” is free to read here on the web, and the Learn AI with Python course includes 5 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.

What will I learn in “Return Values”?

Discover how to use return values to make functions more versatile. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Learn AI with Python?

No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 5, so you can start here or from the beginning and move at your own pace.

How long does the “Return Values” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Learn AI with Python lesson?

Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What is a Function?
  2. Return Values
  3. Scope and Lifetime of Variables
  4. Built-in Functions vs. User-Defined Functions
  5. Importing Modules
← Back to Learn AI with Python