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.

Related course: Complete Python Bootcamp: Go from zero to hero in Python


Create a function getPerson(). As you already know a function can return a single variable, but it can also return multiple variables.

We’ll store all of these variables directly from the function call.

#!/usr/bin/env python3

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

name,age,country = getPerson()

This will output:

multiple return


Try the exercises below:

  1. Create a function that returns a,b and a+b
  2. Create a function that returns 5 variables

After completing these continue with the next exercise.

Download answers