# Python | Difference Between List and Tuple

• Difficulty Level : Easy
• Last Updated : 06 Dec, 2022

List and Tuple in Python are the classes of Python Data Structures. The list is dynamic, whereas the tuple has static characteristics. This means that lists can be modified whereas tuples cannot be modified, the tuple is faster than the list because of static in nature. Lists are denoted by the square brackets but tuples are denoted as parenthesis.

## List vs Tuple

### Test whether tuples are immutable and list are mutable

Here we are going to compare the list and tuple mutability test.

## Python3

 `# Creating a List with``# the use of Numbers``# code to test that tuples are mutable``List` `=` `[``1``, ``2``, ``4``, ``4``, ``3``, ``3``, ``3``, ``6``, ``5``]``print``(``"Original list "``, ``List``)` `List``[``3``] ``=` `77``print``(``"Example to show mutability "``, ``List``)`

Output:

```Original list  [1, 2, 4, 4, 3, 3, 3, 6, 5]
Example to show mutability  [1, 2, 4, 77, 3, 3, 3, 6, 5]```

We can see here tuple can not be modified.

## Python3

 `# code to test that tuples are immutable` `tuple1 ``=` `(``0``, ``1``, ``2``, ``3``)``tuple1[``0``] ``=` `4``print``(tuple1)`

Output:

```Traceback (most recent call last):
tuple1[0]=4
TypeError: 'tuple' object does not support item assignment```

### Test whether tuples are memory efficient.

As tuples are stored in a single memory block therefore they don’t require extra space for new objects whereas the lists are allocated in two blocks, first the fixed one with all the Python object information and second a variable sized block for the data.

## Python3

 `import` `sys``a_list ``=` `[]``a_tuple ``=` `()``a_list ``=` `[``"Geeks"``, ``"For"``, ``"Geeks"``]``a_tuple ``=` `(``"Geeks"``, ``"For"``, ``"Geeks"``)``print``(sys.getsizeof(a_list))``print``(sys.getsizeof(a_tuple))`

Output:

```120
64```

### Test whether implication of iterations is comparatively faster in tuples

As tuples are stored in a single memory block therefore they don’t require extra space for new objects as they are immutable whereas the lists are allocated in two blocks, first the fixed one with all the Python object information and second a variable sized block for the data which makes them even more faster.

## Python3

 `import` `sys, platform``import` `time` `l``=``list``(``range``(``100000001``))``t``=``tuple``(``range``(``100000001``))` `start ``=` `time.time_ns()``for` `i ``in` `range``(``len``(t)):``    ``a ``=` `t[i]``end ``=` `time.time_ns()``print``(``"Total lookup time for Tuple: "``, end ``-` `start)` `start ``=` `time.time_ns()``for` `i ``in` `range``(``len``(l)):``    ``a ``=` `l[i]``end ``=` `time.time_ns()``print``(``"Total lookup time for LIST: "``, end ``-` `start)`

Output:

```Total lookup time for Tuple:  7038208700
Total lookup time for LIST:  19646516700```

My Personal Notes arrow_drop_up