Difference between list and tuple in python with example : In this article we will learn Difference between list and tuple in python with example. List and Tuple in Python are the class of data structure. The list is dynamic, whereas tuple has static characteristics.
Lists:- The list is the changeable data structure, an ordered sequence of elements. The element present inside the list is called the item. The list is defined in the square brackets as []. It is the collection of the changeable and ordered sequence of the elements. The list is used when you want to work on many values. List in Python is the data type in python which is written a list of a comma and separated by the square brackets. The list is called as the homogenous means the sequence that deals with the same kind of things.
Tuples:-
The tuple is the sequence of the immutable python objects and sequence like the list. A Tuple is written in the parenthesis and simple to create. Tuples are the collection of the unchangeable and ordered values and written in the round brackets (). In tuple, the values are immutable so values cannot be changed. The use of tuple is for grouping the data.
The list is mutable means the data can be modified and tuple is immutable means the data cannot be modified.
The list works on big size than the tuple and is faster operation.
The list has the variable length and tuple has fixed length.
The List has more functionality compared to the tuple.
The tuples are heterogeneous means the tuple is sequence which has different types of entries.
Sr.no |
list |
Tuple |
1 |
The list will consume more memory. |
Tuple will consume less memory compared with the list. |
2 |
The list is a group of the values separated by commons and square brackets are important |
Tuples is collection of the values with comma and parenthesis. |
3 |
The iteration us Time consuming |
This implication us faster |
4 |
The list is performing better operations like insertion and deletion. |
The tuple is good for accessing the data elements. |
5 |
The list is a built-in method |
Tuple do not have build in method |
6 |
It is mutable |
This is immutable |
7 |
If contents are changing then we should use the list |
Tuples are used if contents are fixed and not changing. |
8 |
The list-objects cannot be used as the keys because the key should be immutable. |
In tuples the object will be used as the keys if keys are immutable. |