1. Concept library
  2. Python Foundations
  3. Module 9: Classes and objects

Concept

Classes and instances

A class describes a kind of thing: the data each one carries and what it can do. Each instance is one such thing with its own values. __init__ sets those values up.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain what a class describes and what an instance holds
  2. Write a class with __init__ that sets up each instance's own data
  3. Spot the shared class attribute that was meant to be per-instance

In practice

A few lines that show Classes and instances doing its job.

Python
class Account:
    def __init__(self, owner, balance=0):
        self.owner = owner
        self.balance = balance

a = Account("Ada", 50)
b = Account("Grace")
a.balance += 25
print(a.balance, b.balance)    # 75 0

The common mistake

Watch for

Defining data at class level, like balance = [] under class Account, and expecting each instance to get its own. Class attributes are shared by every instance; per-object data belongs in __init__.

What to know first

Your roadmap puts these before Classes and instances, unless you already know them.

How it stays learned

Once a session shows you understand Classes and instances, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Classes and instances.

Next in the moduleMethods and self →