← Courses

Python for AI — Beginner Foundations

Data Science

Functions · Lesson 42 of 76

Return values

return sends a value back out of a function so the rest of your program can use it. This is different from print(), which only shows something on screen.

Python

A function can return more than one value at once (as a tuple):

Python

Remember: print shows, return gives back. You usually want return so the value can be reused.

Your turn: write half(n) that returns n / 2, store half(50) in a variable, and print it.

Check your understanding

Exercise — check your understanding

Write stats(numbers) that returns the smallest and the largest value, in that order.

You’re reading for free. Sign in to keep your progress and earn a certificate when you finish.Sign in to keep my progress →