Python Program to Return Multiple Values From a Function

To understand this example, you should have the knowledge of the following Python programming topics:


Example 1: Return values using comma

Output

('John', 'Armin')
John Armin

When you return multiple values using comma(s), they are returned in the form of a tuple. As shown in the code above, two strings "John" and "Armin" are returned with a single return statement.


Example 2: Using a dictionary

Output

{1: 'John', 2: 'Armin'}

When you return values using a dictionary, it is easy for you to keep track of the returned values using the keys. The return statement returns the two variables in the form a dictionary.