Duration: 90 Minutes | Topic: Object-Oriented Programming (OOP)

Goal: Understand why we use classes.
Explanation for Student: Imagine you want to build a house. You don't just start building randomly. You need a Blueprint (a plan).
Goal: Learn class, __init__, and self.
Code Example:
class Dog:
# The "Constructor" - This runs when we create a new dog
def __init__(self, name, breed, age):
self.name = name # Attribute
self.breed = breed # Attribute
self.age = age # Attribute # A Method (What the dog can DO)
def bark(self):
print(f"{self.name} says: Woof! Woof!")# --- Creating Objects ---
my_dog = Dog("Buddy", "Golden Retriever", 3)
your_dog = Dog("Lucy", "Poodle", 5)print(my_dog.name) # Output: Buddy
my_dog.bark() # Output: Buddy says: Woof! Woof!
Key Concepts for Student:
__init__: The "Starting Point." It sets up the object's information.self: Refers to "this specific object." When Buddy barks, self.name is Buddy. When Lucy barks, self.name is Lucy.Goal: Practice creating attributes and basic methods.
Task: Create a class called Hero for an RPG game.
name, health (default 100), power.rest() -> Increases health by 10.stats() -> Prints the hero's current status.Solution Template (Don't show the student yet!):
class Hero:
def __init__(self, name, power):
self.name = name
self.power = power
self.health = 100 def rest(self):
self.health += 10
print(f" {self.name} is resting. Health is now {self.health}") def stats(self):
print(f" Hero: {self.name} | HP: {self.health} | Power: {self.power}")# Student should test it:
p1 = Hero("Zelda", 25)
p1.stats()
p1.rest()
Goal: Learn how two objects interact with each other.
Explanation for Student: Objects aren't just isolated. They can interact! We can pass one object into the method of another object.
Code Extension:
class Hero:
def __init__(self, name, health, power):
self.name = name
self.health = health
self.power = power def attack(self, enemy):
print(f"️ {self.name} attacks {enemy.name}!")
enemy.health -= self.power
print(f" {enemy.name} now has {enemy.health} HP left.")# Creating two heroes
hero = Hero("Link", 100, 20)
monster = Hero("Ganon", 200, 10)# Let the interaction happen
hero.attack(monster)
Goal: Independent coding to consolidate everything.
Instructions for Student:
Create a class BankAccount.
owner (string), balance (number).deposit(amount): Adds money to balance.withdraw(amount):
| Concept | Python Syntax | Meaning |
|---|---|---|
| Create a Class | class Name: | Define the blueprint |
| Initialize | def __init__(self, ...): | Set the starting stats |
| Identity | self | Referring to "this specific" object |
| Action | def method_name(self): | What the object can do |
| Instance | obj = Name() | Making a real thing from the blueprint |
TypeError: __init__() takes 3 positional arguments but 4 were given
self in the __init__ definition.NameError: name 'health' is not defined
health instead of self.health.Grok写作使用方法有哪些常见错误?5步纠正
通义千问使用技巧2026版:问对3类问题才能获得精准答案
蚂蚁庄园2026年2月12日题目答案最新
Google rotate antigravity 限流额度 报错怎么处理?原因、排查和修复方法
Claude GitHub 是什么?源码、功能和适用场景说明
Claude 插件 vibecontrols Vibe Plugin AI Minimax 工作流怎么搭?流程、工具和落地步骤