Computer Science

When would you prefer tuples over lists ?

Python Tuples

6 Likes

Answer

Tuples are preferred over lists in the following cases:

  1. When we want to ensure that data is not changed accidentally. Tuples being immutable do not allow any changes in its data.
  2. When we want faster access to data that will not change as tuples are faster than lists.
  3. When we want to use the data as a key in a dictionary. Tuples can be used as keys in a dictionary, but lists cannot.
  4. When we want to use the data as an element of a set. Tuples can be used as elements of a set, but lists cannot.

Answered By

4 Likes


Related Questions