Difference between python's tuple and list

Anna report abuse

Hi everyone! Can you tell me, what is the major difference between Python's tuple and list? And in what cases usage of tuple instead of the list will be more efficient?

Answers

PyAnto report abuse __ edited

Hi Anna,

A tuple is a collection of values, and it is declared using parentheses. However, we can also use a tuple packing to do the same, and unpacking to assign its values to a sequence. Unlike in C++, we don’t have arrays to work with in Python. Here, we have a list instead.

The main difference is that tuple is immutable, list is mutable. This means that lists can't be a key in a dictionary, they can be rearranged, deleted and reassigned.

Hope that helps :)

Anna report abuse

Thanks. It is helpful indeed. )

Add Answer

Need support?

Just drop us an email to ... Show more