← Courses

Python for AI — Beginner Foundations

Data Science

Classes · Lesson 44 of 76

Classes

Let's look more carefully at the parts of a class.

Python
  • class BankAccount: names the blueprint (classes use CapitalisedNames).
  • __init__ is the constructor — it runs once, when you create an object.
  • self.owner and self.balance are attributes: data that belongs to each object.

Every object you create gets its own copy of those attributes, so two accounts can hold different balances.

Your turn: make a second account for "Emeka" with balance 1000 and print his balance.

You’re reading for free. Sign in to keep your progress and earn a certificate when you finish.Sign in to keep my progress →