← Python

OOP – __init__ Method

__init__ is called automatically when an object is created and sets up its initial attributes

What it does: __init__ runs automatically when Dog('Rex') is called. self.name stores the value. Once set in __init__, the attribute is accessible on the object as d.name. Dog('Rex') creates the object and immediately calls __init__ with 'Rex'. Python uses self (not this) — it's the reference to the object being created. Dunder (double-underscore) methods always have two underscores on each side. Parameters after self become the arguments you pass when creating the object. Without __init__ you can still create objects — they just won't have initial attributes. __init__ must take 'self' as its first parameter. Without it, Python passes the instance and causes a TypeError.

Common mistakes: Missing self as the first parameter. Need DOUBLE underscores: __init__ not _init_.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What does __init__ do?
Initializes a new object automaticallyDeletes the object
Matches
❌ class Dog: def __init__(name): self.name = name
Error: First param must be 'self'
Applying
Meanings
Term
__init__
Meaning
Constructor method that runs automatically when an object is created.
Practice
class Dog:
Testing
Gaps
def (self, name):
Check Answer
Spots
1class Dog:
2 def __init__(name):

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Tree Frog' badge — Leap of Logic, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What does __init__ do?
A. Initializes a new object automatically ✓
B. Deletes the object
__init__ sets up the object's initial state — it's called automatically on creation
2. When does __init__ run?
A. When an object is deleted
B. When an object is created ✓
Dog('Rex') creates the object and immediately calls __init__ with 'Rex'
3. What must be the first parameter of __init__?
A. self ✓
B. this
Python uses self (not this) — it's the reference to the object being created
4. class Dog:\n def __init__(self, name):\n self.name = name\nDog('Rex') what is self.name?
A. 'name'
B. 'Rex' ✓
self.name = name stores the argument — so self.name holds 'Rex', not the string 'name'
5. Do you pass 'self' when creating an object?
A. No Python passes it automatically ✓
B. Yes
Python injects self automatically — Dog('Rex') calls __init__(dog_instance, 'Rex')

Match the Pairs

class Dog: def __init__(name): self.name = name Error: First param must be 'self'
class Dog: def __init__(self, name): self.name = name Dog() Error: Missing required arg 'name'
class Dog: def __init__(self, name): self.name = name Valid: __init__ with parameter
d = Dog('Rex') print(d.name) Ok: Access attribute after creation
class Dog: def __init__(self,n): self.name=n d=Dog('Rex') print(d.name) Output: Rex
class Point: def __init__(self,x,y): self.x=x self.y=y p=Point(3,4) print(p.x) Output: 3

Key Term

__init__
Constructor method that runs automatically when an object is created.~~self

Fill in the Blanks

1. class Dog: def __init__(self, name): self.name = name
2. class Dog: def __init__(self): self.name = name
3. class Dog: def __init__(self, name): self.name = name
4. dog = Dog('Rex') print(dog.name)
5. class Person: def __init__(self, name, age): self.age = age

Spot the Error

Question 1
A class Dog:
B def __init__(name):
C self.name = name
Line B — Missing self as the first parameter
Question 2
A class Dog:
B def _init_(self, name):
C self.name = name
Line B — Need DOUBLE underscores: __init__ not _init_
Question 3
A class Dog:
B def __init__(self, name):
C name = name
Line C — Must use self.name to save on the object. name alone is just a local variable.
Question 4
A class Dog:
B def __init__(self, name):
C self.name = name
D
E dog = Dog()
F print(dog.name)
Line E — __init__ expects a name argument Dog() without it causes TypeError
Question 5
A class Dog:
B def __init__(self, name):
C self.name = name
D
E dog = Dog('Rex', self)
Line E — Don't pass self Python does it automatically
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?