What are lists and tuples? What is the key difference between the two?

Last updated 4 weeks ago | 29 views 75     5

Tags:- Python

Python | lists, and tuples

Lists and Tuples both are sequence data types that can store a collection of objects in Python. They are both heterogeneous data types means that you can store any kind of data type

The key difference between the tuples and lists is that while the tuples are immutable objects the lists are mutable. This means that lists can be modified, appended, or sliced on the go but tuples remain constant and cannot be modified in any manner.

 

List vs Tuple

The table below includes the basic difference between list and tuple in Python.
 

List Tuple
It is mutable It is immutable
The implication of iterations is time-consuming in the list. Implications of iterations are much faster in tuples.
Operations like insertion and deletion are better performed. Elements can be accessed better.
Consumes more memory. Consumes less memory as compared to the list.
Multiple in-built methods. Comparatively lesser built-in methods in them.
The list operations are comparatively much more error-prone.  Tuples operations are safe and not very error-prone.
 

Lists are represented with square brackets
['sara', 6, 0.19]

 

Tuples are represented with parentheses
('ansh', 5, 0.97)