Object-Oriented Programming

Lesson 13 of 20

Meet classes, objects, __init__ and self — build your first object step by step and see where its data lives.

The big picture

Blueprints and the things they build

A class describes what every Dog is like; an object is one actual dog, built from the blueprint and carrying its own data.

Blueprints, Not Things

class Dog: stores a description; Dog("Rex") builds one real object from it.

__init__ Sets Up

Creating an object automatically runs __init__, which stores the starting attributes.

self = This Object

Inside methods, self is whichever object the call went through — rex or bella.

Objects Hold State

Attributes live on the object, so two Dogs can carry different names side by side.