Welcome to Chapter 7: Classes & Objects! 🏗️
💡 Think of it like this: A class is like a blueprint for building a house. The blueprint describes what a house looks like, but it's not a house itself. When you build a house from that blueprint, that's an object!
Key concepts:
class — Creates a blueprint (starts with capital letter!)__init__ — The constructor, runs when you create an objectself — Refers to the current object (like "me" in English)self.name)bark())In this exercise, you'll create a Restaurant class — think of it as the blueprint for any restaurant! 🍔
# The blueprint (class)
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
def bark(self):
print(f'{self.name} says: Woof! 🐕')
# Creating objects (instances)
rex = Dog('Rex', 'Labrador')
buddy = Dog('Buddy', 'Golden Retriever')
rex.bark() # Rex says: Woof! 🐕
buddy.bark() # Buddy says: Woof! 🐕
Run your code
Pizza Palace serves Italian food. Rating: 4.5/5
Sushi House serves Japanese food. Rating: 4.8/5