Collections in Python: Work with Groups of Values
Collections let you group related data together. In Python, the most common types are lists, tuples, dictionaries, and sets.
What each type is best for
-
list: ordered, changeable sequence -
tuple: ordered, fixed sequence -
dict: key-value pairs -
set: unique values
Example
shopping_list = ["milk", "bread", "eggs"]
student = {"name": "AyÅŸe", "age": 22, "major": "Computer Science"}
visited_cities = {"Istanbul", "Ankara", "Izmir"}
Real-world use cases
-
listfor a to-do list or shopping cart -
dictfor user profiles or configuration -
setfor unique IDs or tags
Why this matters
Most programs are about managing collections of items, not just single variables. Mastering collections prepares you for data processing, APIs, and apps.
Next
Use these collections with loops and functions to create robust programs.
Top comments (0)