Lesson 5
Writing Reusable and Self-explanatory Programs
Chapter 5: Advanced function features
Returning multiple objects
A function can usually return only one object.
def move_right(x):
return x + 1
new_x = move_right(2)
print(new_x)
In Python, you can also return multiple objects.
To be more precise, you can return a single tuple
object (a bit like a vector), which can be made up of more than one basic object! We will cover tuples in a future lesson. For now, just exploit this useful Python feature when needed!
1 2 3 4 5 6 7 8 9 10 11 |
|
Output:
2
3
(2, 3)
<class 'tuple'>