In Python, a collection (or container) is a data structure used to group multiple items together into a single object, allowing you to store, manage, and iterate through data efficiently.
Key Characteristics
-
Categories: Collections are organized by how they access dataβSequences (positional indexing like list, tuple, str), Sets (unordered unique values like set, frozenset), and Mappings (key-value pairs like dict).
-
Mutability: They are classified as either mutable (can be modified in place, e.g., list, dict, set) or immutable (cannot be altered after creation, e.g., tuple, str, frozenset).
-
Common Operations: Virtually all collections support membership checking (in), iteration using loops (for x in container), and size retrieval (len()).
(Note: Beyond built-in types, Python also includes a standard collections module providing specialized data structures like deque, Counter, defaultdict, and namedtuple.)