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:
Comments
write a comment