Red Hat – OOP & File Handling
advanced30 XP

Classes & Objects

Model real-world things as classes and objects

Classes & Objects

Python
class Dog:
    def __init__(self, name, breed):
        self.name = name
        self.breed = breed

    def bark(self):
        print(f"{self.name} says: Woof!")

buddy = Dog("Buddy", "Labrador")
buddy.bark()  # Buddy says: Woof!
⌨️

Type it yourself

Don't just read it — type the example from above into the box, press Run ▶, and watch what happens. Typing it yourself is how it really sticks! Stuck? Tap Show example.

Python · Playground
Output
Press ▶ Run to see your code come to life…

Quick check

01/2

What does __init__ do?