Ch 10 · Dictionaries & Classes · Python
Topic 10 of 13 in Python — Complete Tutorial (Beginner) — 3 lessons.
What is a Dictionary?
A dictionary stores data as key-value pairs. While a list is a numbered sequence accessed by position, a dictionary is a labelled collection accessed by name. A student ID card is the perfect example: it groups a name, roll number, and class together, each with a clear label. In Python you write a dictionary with curly braces, putting a colon between each key and its value: {"name": "Ali", "age": 12}.
Lists of Dictionaries
The real power appears when you combine lists and dictionaries. A single dictionary describes one thing — one student. A list of dictionaries describes a whole collection — an entire class. This pattern models almost any real-world dataset, because real data comes as lists of items that each have several labelled fields. To process it, you loop over the list and use key access inside the loop.
Classes: Blueprints with Behaviour
A class takes the idea of grouped data one step further: it bundles data together with the functions that work on that data. The functions inside a class are called methods. A class is a blueprint — you define it once, then create as many individual objects (instances) from it as you need. Each instance has its own data but shares the same methods.
All topics in Python Beginner
- Introduction to Programming & Python
- Your First Python Program
- Variables — Your Data Containers
- Data Types — Kinds of Values
- Operators & Expressions
- Conditional Statements
- Loops & Iterations
- Functions
- Lists — Collections of Data
- Dictionaries & Classes
- Strings — Working with Text
- Error Handling
- Mini-Projects & Practice