Aggregate TypesΒΆ

>>> l = [1, 2.0, "three"]       # List
>>> t = (1, 2.0, "three")       # Tuple
>>> s = {1, 2.0, "three"}       # Set  (v2.7+)
>>> d = {"key1":1, "key3":3.0}  # Dictionary
  • Tuples are immutable (read-only) objects, others are mutable (modifiable)
  • Aggregate objects (including strings) are iterable
>>> (l[0], t[1], d['key3'])
(1, 2.0, 3.0)
>>> l[0] = 10
>>> l
[10, 2.0, 'three']
>>> t[0] = 10
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment