728x90
반응형
# 생성자 : 인스턴스를 만들 때 호출되는 메서드
class Monster :
def __init__(self, health, attack, speed) :
self.health = health
self.attack = attack
self.speed = speed
def decrease_health(self, num) :
self.health = num
def get_health(self) :
return self.health
# 인스턴스 생성
goblin = Monster(800, 120, 400)
goblin.decrease_health(100)
print(goblin.get_health())
728x90
반응형
'Programming > Python' 카테고리의 다른 글
[Python] 파이썬 상속 오버라이딩 / 클래스 변수 (0) | 2025.01.31 |
---|---|
[Python] 파이썬 상속 - 오버라이딩/오버로딩 (0) | 2025.01.31 |
[Python] 파이썬 클래스와 객체 (0) | 2025.01.31 |
[Python] 파이썬 딕셔너리 dictionary (0) | 2025.01.16 |
[Python] 파이썬 튜플 tuple (0) | 2025.01.16 |