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() print(name) print(age) print(country)
Try the exercises below:
1. Create a function that returns a,b and a+b
After completing these continue with the next exercise.