Skip to main content

Unit 2 · Python mode... Activate! · Lesson 15 of 57

Returning Ruckus

To return, or not to return.

In the last lesson, I told you return is a REALLY important concept. I wasn't kidding!

But instead of me explaining it, let's just try it.

Here's our add function from before, and on the last line, we call it:

def add(number1, number2):
    return (number1 + number2)

add(2, 3)

2 + 3 is 5. Easy.

But before you press Run, I want you to make a guess.

Question

Answer it in the lesson and it is checked as soon as you send it. Create a free account to do this part.

Press Run and see what happens. Don't change anything yet!

Python exercise

Write the program in an editor next to the lesson, run it, and have it checked automatically. Create a free account to do this part.

Wait... where's the 5?!

If you guessed 5, don't worry, so did everyone else. (Yes, including me the first time.)

But the console is completely empty. Nothing. Nada.

We told Python to add 2 and 3, and it definitely did the math... so where did the 5 go?

Hold that thought. We'll figure it out in the next lesson!

Do this lesson for real

With a free account you get the terminals, challenges and checks that go with the lessons in Intro to Python, and your progress is saved as you go. CyberAcad is a 501(c)(3) nonprofit, so there is nothing to pay.