what is difference between list and tuple in python?

The differences between tuples and lists is , tuples cannot be changed unlike lists. tuples use parentheses, whereas lists use square brackets.

Python list example

Run the code

Let us change the 3rd list object


Python tuple example


  • We cannot change tuple objects. for example below code would give error.

difference between list and tuple in python

  • List objects are mutable and thus they can’t be used as a key in the dictionary, while tuples can be used as key in dictionary.

  • List objects can be changed while tuples are not changed.
  • Lists are homogeneous while tuples are usually heterogeneous.
  • Lists are for variable length, tuples are for fixed length.




Related Contents to follow