Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string format
#1
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'>
Reply
#2
Gold needs to be instantiated:
gg = Gold(25)
print(gg)
results:
Output:
Gold ===== A Round Coin Value: 25
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Set string in custom format korenron 4 1,102 Jan-16-2023, 07:46 PM
Last Post: mutantGOD
  Format String NewPi 2 949 Oct-10-2022, 05:50 PM
Last Post: NewPi
  TypeError: not enough arguments for format string MaartenRo 6 2,944 Jan-09-2022, 06:46 PM
Last Post: ibreeden
  string format challenge jfc 2 1,788 Oct-23-2021, 10:30 AM
Last Post: ibreeden
  Print first day of the week as string in date format MyerzzD 2 2,027 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  string.format() suddenly causing errors with google drive API zwitrader 0 1,770 Jun-28-2021, 11:38 PM
Last Post: zwitrader
  String to Date format SAF 2 2,470 Apr-06-2021, 02:09 PM
Last Post: snippsat
  MySQLdb._exceptions.ProgrammingError: not enough arguments for format string. farah97 0 3,339 Jan-22-2020, 03:49 AM
Last Post: farah97
  Highlight/Underline a string | ValueError: zero length field name in format searching1 1 3,025 Jul-01-2019, 03:06 AM
Last Post: metulburr
  write image into string format into text file venkat18 2 4,416 Jun-01-2019, 06:46 AM
Last Post: venkat18

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020