I am currently learning Python. Since I am a big fan of OO (object-oriented) programming, obviously it's not hard to apply it in Python. But when I tried it, it seems very different to C#.
As you can see below, I am trying to create a character class, with three attributes Id, Hp, and Mana. The score is calculated by adding up Hp and Mana and then times 10.
As you can see, after defining MyChar where id=10 hp=100 mana=100
, I was expecting MyChar.Score
is (100+100)*10, which is 2000, but weirdly, it says:
bound method Character.Score of <__main__.Character object at 0x0000021B17DD1F60>
as the result of print(MyChar.Score)
.
How can I fix this problem?
Here is my code:
class Character:
def __init__(self, Id, Hp, Mana):
self.Id = Id;
self.Hp = Hp;
self.Mana = Mana;
def Score(self):
return (self.Hp + self.Mana)*10;
MyChar = Character(10, 100, 100);
print(MyChar.Score)