Python Forum
string format - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: string format (/thread-8627.html)



string format - ShaneP - Mar-01-2018

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'>



RE: string format - Larz60+ - Mar-01-2018

Gold needs to be instantiated:
gg = Gold(25)
print(gg)
results:
Output:
Gold ===== A Round Coin Value: 25