Aug-16-2019, 06:46 PM
(Aug-16-2019, 01:57 PM)ThomasL Wrote:def getStats(self): print(self.strength, self.dexterity, self.wisdom, self.intelligence)It´s a bad idea to use print() to print class values in a class method.
There are two better ways:
1)
def get_stats(self): return f"{self.strength}, {self.dexterity}, {self.wisdom}, {self.intelligence}"Then you can print player stats like this:
print(player.get_stats())But please have a look at Python PEP8 code style. and name your functions and methods properly.
2)
def __str__(self): return f"{self.strength}, {self.dexterity}, {self.wisdom}, {self.intelligence}"Replace your obsolete method getStats() and use the dunder-method __str__()
Then you can easily print the player stats like this
print(player)
Woah, thanks for taking the time to explain everything thoroughly, it goes a long way with helping me understand this stuff. I'll have a peek at PEP 8 and see if I can improve the readability of my code for you guys, as I'm sure you'll be seeing me from time to time whenever I hit a wall and google doesn't solve my problem. I most definitely need to look into dunder-methods so I can clean up obsolete methods like the one you pointed out. Thanks again for the info!