Python Forum

Full Version: string format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm pretty new to python & programming in general. I cant figure out how to print gold as a string.

 class Item:
    def __init__(self, name, description, value):
        self.name = name
        self.description = description
        self.value = value


    def __str__(self):
        return "{}\n=====\n{}\nValue: {}\n".format(self.name, self.description, self.value)


class Gold(Item):
    def __init__(self, amt):
        self.amt = amt
        super().__init__(name='Gold', description='A Round Coin', value=self.amt)


print(Gold) 
Output:
<class '__main__.Gold'>
Gold needs to be instantiated:
gg = Gold(25)
print(gg)
results:
Output:
Gold ===== A Round Coin Value: 25