- 클래스 (Class) 란?
- 객체 생성을 위한 내용이 담긴 명세서 (설계도)
- 연관되어있는 메소드와 변수의 집합
- 인스턴스 (Instance) 란?
-
구현된 각각의 객체
- 실체화된 객체에 각각의 메모리가 할당된 상태
# 클래스 Monster
class Monster:
def __init__(self, name, health, damage) -> None:
self.name = name
self.health = health
self.damage = damage
pass
def info(self):
print(f"{self.name}의 남은 체력 : {self.health} ")
print(f"{self.name}의 현재 공격력 : {self.damage} ")
def attack(self, target):
target.health -= self.damage
def run(self, target):
...
ogre = Monster("Balbos", 500, 50)
goblin = Monster("shylock", 100, 10)
goblin.attack(ogre)
ogre.info()
Monster 클래스를 토대로 만들어진 Monster 객체 ogre, goblin
ogre와 goblin은 각각의 인스턴스
ogre와 goblin은 객체(Monster)를 나타내는 클래스(Monster 클래스)의 2개의 다른 인스턴스