DEV Community

Nicholus Mush
Nicholus Mush

Posted on

Collections in Python

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"}
Enter fullscreen mode Exit fullscreen mode

Real-world use cases

  • list for a to-do list or shopping cart
  • dict for user profiles or configuration
  • set for 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)