Programming/Python
[Python] 파이썬 생성자
prinha
2025. 1. 31. 11:04
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
반응형