Skip to content

Exercise 15: Multiple return

Alternative course

Multiple return

Python functions can return multiple variables. These variables can be stored in variables directly. A function is not required to return a variable, it can return zero, one, two or more variables.

This is a unique property of Python, other programming languages such as C++ or Java do not support this by default.


#!/usr/bin/env python3

def getPerson():
    name = "Leona"
    age = 35
    country = "UK"
    return name,age,country

name,age,country = getPerson()

What you see if successful

You should see that the variables are directly saved from the function.


Study drill

Try the exercises below:

1. Create a function that returns a,b and a+b

After completing these continue with the next exercise.


Exercise 14 : Slices
Exercise 16: Scope
Published inUncategorized

Be First to Comment

    Leave a Reply