Difference Between List and Tuple in Python
By BYJU'S Exam Prep
Updated on: September 25th, 2023
Difference Between List and Tuple in Python: The list and tuple are the class of data structure of python. The list is dynamic, but the tuple has a static characteristic. The major difference between List and Tuple in Python is that list is dynamic in nature whereas the Tuple is not dynamic in nature.
Lists and Tuples are used to store one or more data types or python objects sequentially. Both can store any data such as float, integer, string, and dictionary. Lists and Tuples are similar in most factors, but we will describe the main difference between them.
Table of content
Difference Between List and Tuple
The table shows the critical difference between List and Tuple. This table discusses the difference between List and Tuple based on methods, memory occupy, representation, nature, etc.
Key Differences Between List and Tuple
LIST |
TUPLE |
The list is mutable means suppose we have a list. L=[1,2,3], and we have to add one more element than we add. |
The tuple is immutable means it, once declared, cannot expand. |
The list is dynamic in nature |
Tuples are fixed size in nature. |
The list is enclosed in a square bracket[]. |
Tuples are enclosed in parenthesis(). |
The list can be used when the data is used frequently. |
The tuple can be used when data cannot be changed. |
There are several built-in methods in the list. |
The tuple does not have many built-in methods as list. |
List occupies more memory |
Tuple occupies less memory as compared to list. |
What is the List?
Before knowing the difference between List and Tuple, let us discuss the list. The list represents the group of elements. The list is very similar to an array, but the significant difference is that the list stores different types type of elements, whereas an array can store only one type of element.
The list contains different types of elements that can be modified. However, the list is dynamic, which means the size of the list is not fixed.
The syntax for creating the list is as follows:
List_name = [element1, element2, ………]
Example: list = [1, 2, 3, ‘BYJU’S’, -5]
The syntax for creating the empty list is as follows:
List_name = []
Example: list = []
What is a Tuple?
Before knowing the difference between List and Tuple, let us discuss tuple. The tuple represents a group of elements that can be the same or different types. The tuples are similar to the list, but tuples are read-only, which means we cannot modify their elements. Therefore, the tuples occupy less memory as compared to the list.
The syntax for creating the empty tuple is as follows:
Tuple_name = ()
Example: tuple = ()
The syntax for creating the tuple is as follows:
We can create a tuple by writing the elements separated by commas inside the parenthesis().
Tuple_name = (element1, element2)
Example: tuple = (2, 3, ‘BYJU’S’, -5)
The syntax for creating the tuple with one element is as follows:
Tuple_name = (element1, element2)
Check out some important topics related to the difference between List and Tuple in the table provided below: