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.

Published on 18-Apr-2018 12:47:34