Python Collections


In Python, collections are containers that hold multiple elements.

  • common built-in collections:
    1. Lists (list):
      • Ordered, mutable sequences
      • Elements can be of different types
    2. Tuples (tuple):
      • Ordered, immutable sequences
      • Typically used for fixed collections
    3. Sets (set):
      • Unordered, mutable collections of unique elements
    4. Dictionaries (dict):
      • Ordered, mutable key-value pairs
      • Efficient for lookups
      • In Python 3.7, dictionaries are ordered
      • In Python 3.6 and earlier, dictionaries are unordered
    5. Strings (str):
      • Ordered, immutable sequences of characters

Kinds