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

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

I. 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];

II. Mutable: Tuple is an immutable data structure. Whereas, a List is a mutable data structure.

III. Size: A Tuple takes much lesser space than a List in Python.

IV. Performance: Tuple is faster than a List in Python. So it gives us good performance.

V. 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.


Posted

in

Tags:

Comments

Leave a Reply