What is the difference between a Tuple and a List in Python?

In Python, Tuple and List are built-in data structures.
Some of the differences between Tuple and List are as follows:

  • Syntax: A Tuple is enclosed in parentheses:
    E.g. myTuple = (10, 20, “apple”);
    A List is enclosed in brackets:
    E.g. myList = [10, 20, 30];
  • Mutable: Tuple is an immutable data structure. Whereas, a List is a mutable data structure.
  • Size: A Tuple takes much lesser space than a List in Python.
  • Performance: Tuple is faster than a List in Python. So it gives us good performance.
  • Use case: Since Tuple is immutable, we can use it in cases like Dictionary creation. Whereas, a List is preferred in the use case where data can alter.
Read the full book at www.amazon.com
Posted in Python, Python Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*