Skip to main content

Class in Python

Published 1 min readMarkdown
Part of seriesPython

how to track the HP of all characters?

image.png

It's better to make each character has its own HP. This is where Class comes in handy.

class Monster():
    hp = 100
    mp = 10

    def damage(self, attack):
        self.hp = self.hp - attack

monster1 = Monster()
monster1.damage(120)

monster2 = Monster()
monster2.damage(90)

No comments yet. Be the first to comment.

More from this blog