BeginnerCoder

Lesson 3 — Classes & objects

Objects

A class is a blueprint that bundles data and behaviour together. init runs when you create an object and stores its data on self. Other methods also take self as their first parameter, so they can read that data, like self.name.

class Dog:
    def __init__(self, name):
        self.name = name
    def bark(self):
        return self.name + " says woof"

Why it matters: classes let you model real things — users, orders, shapes — with the data and the actions in one place.

Want it another way?
Task

Add a method area() to Rectangle that returns width times height, then run the print.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.