Return Multiple Values from a Function Using Python Dictionary

When a Python function returns many values, it can be confusing as to which value is returned first, second, or third, etc. A better idea is to return using a Python dictionary like below.

To access 'a', for example, you just need to call values['a']. You don’t need to be worried that you will access the wrong value because of the wrong order.

If you happen to change the order of the outputs in your function, you still access the right value.

 

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran