Lesson 1
Overview
What a class is
A class is a blueprint for making objects. Each object can store its own data and use methods that belong to that class.
class Dog -> blueprint
Dog("Max") -> object / instance
object -> has data + methods
What you should know by the end
- What `class`, `self`, and `__init__` do
- How Python finds attributes
- Class variables vs instance variables
- How inheritance and `super()` work
- When to use a normal class vs `@dataclass`
With class vs without class
Lesson 2
Core Parts
The smallest useful class
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
return f"{self.name} says woof"
`class Dog:`
Defines a new type of object. Python runs the class body and builds a class object from it.
`__init__`
Runs after a new instance is created. It usually puts starting data on the object.
`self`
Means "this current object". It is how a method reads or writes the instance's own data.
One key idea
Dog.bark(dog_object) ^ When you write dog_object.bark(), Python passes the object in as the first argument automatically.
Opinionated rule: use a class when you want this sentence to be true:
"This thing has its own data, and it can do things with that data."
Lesson 3
Creation Flow
What happens on `Dog("Max")`
1. Python creates a new Dog instance 2. Python calls __init__(self, "Max") 3. self.name = "Max" 4. The instance is returned
The full lower-level story is `__new__` creates the object and `__init__` initializes it, but beginners usually work only with `__init__`.
Step through instantiation
Lesson 4
Attribute Lookup
How Python finds `obj.name`
Python checks in this order: instance -> class -> parent class -> grandparent -> error
This lookup rule explains why inherited methods work, why class variables can be shared, and why overriding changes behavior.
Lookup simulator
Animal | +-- move() | Dog | +-- species = "canine" max = Dog() | +-- name = "Max"
Lesson 6
Inheritance
What inheritance gives you
class Animal: def __init__(self, name): self.name = name def speak(self): return "some sound" class Dog(Animal): def speak(self): return "woof"
Animal ^ | Dog
`Dog` reuses what `Animal` already has and changes only what is special about a dog.
`super()` flow
Practical advice: inheritance is useful, but do not force it everywhere. If two things are only loosely related, plain composition is often cleaner.
Lesson 7
Special Methods and Helpful Tools
`__str__` and `__repr__`
These control how objects show up when printed or inspected. They make your objects readable.
`@classmethod` and `@staticmethod`
`classmethod` receives the class as `cls`. `staticmethod` receives neither class nor instance automatically.
`@property` and descriptors
Properties let attribute access trigger logic. Under the hood, that uses Python's descriptor machinery.
Normal class vs `@dataclass`
from dataclasses import dataclass @dataclass class User: name: str age: int
Use `@dataclass` when the main job is holding data. Python can generate `__init__`, `__repr__`, and comparison methods for you.
Use a normal class when you need custom behavior, custom construction, or richer control over state.
Flip cards
Lesson 8
Practice and Quiz
Mini practice
1. Write a `Book` class with `title` and `author`.
2. Add a `describe()` method that returns `"Title by Author"`.
3. Change it to `@dataclass`. What code disappears?
Quick quiz
Reference
Cheat Sheet
Fast syntax
class User:
kind = "person"
def __init__(self, name):
self.name = name
def hello(self):
return f"Hi, I am {self.name}"
Remember this
- `self.x` means per-object data
- `Class.x` may mean shared data
- `obj.method()` passes `obj` in automatically
- Lookup order starts at the instance
- `super()` lets child classes reuse parent logic
Authority
Sources
This course was built from the official Python docs, not random blog posts.