Python Collections
In Python, collections are containers that hold multiple elements.
- common built-in collections:
- Lists (
list):- Ordered, mutable sequences
- Elements can be of different types
- Tuples (
tuple):- Ordered, immutable sequences
- Typically used for fixed collections
- Sets (
set):- Unordered, mutable collections of unique elements
- 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
- Strings (
str):- Ordered, immutable sequences of characters
- Lists (