4.3. Sequence Ordered

4.3.1. Both

  • ordered

  • possible to getitem and slice

  • elements can be duplicated

  • elements of any types

4.3.2. Tuple

  • immutable

  • one contingent block of data in memory

4.3.3. List

  • mutable

  • implemented in memory as list of references to objects

  • objects are scattered in memory

4.3.4. Memory Footprint

>>> from sys import getsizeof
>>>
>>> a = [1, 2, 3]
>>> b = (1, 2, 3)
>>>
>>> getsizeof(a)
120
>>>
>>> getsizeof(b)
64

4.3.5. Memory

../../_images/memory-compare.png

Figure 4.3. Memory representation for list and tuple

4.3.6. Assignments