Why python returns tuple in list instead of list in list?


Python expects you to not mutate data when it returns some data. Tuples are also faster than lists. Tuples are generally used where order and position are meaningful and consistant. So for example, if you have a database driver in python and query for some data, you'll likely get back a list of tuples as the driver expects you to get the data and use it not mutate it. This also ensures that the data is in the same order as the fields you queried.

Updated on: 30-Jul-2019

254 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements