I've looked through many different forum posts and have tried a bunch of different techniques, but I have not figured out how to get my str function to return a string ' ' rather than having no quotations.
My Code:
class Comment:
def __init__(self,commenterName, content):
self.name = commenterName
self.content = content
def __str__(self):
return str('%s: %s' %(self.name, self.content))
From what I understand if I am accompanying my return value in my str function with str() it should return the string value.
Instead...:
>>>Comment("lol","lol")
<__main__.Comment object at 0x000000000354CF60>
I need to specifically return the value as a string rather than print it, that I know.
I am trying to get the output:
"lol": "lol"
but the best I have managed is a:
lol: lol
I have been working on this exact little problem for quite sometime and cannot figure out what I am doing wrong. Thank you for help in advance :D
P.S. I am trying to use
Comment(commenterName,content)
in the terminal so that it returns the value
'commenterName: content'
I'm trying to achieve this without using the print() command in the terminal as well as not using the str() command in the terminal. In my python file however, it is fine, I just need to return the value in some way. I hope this isn't too much of a repost, as I said I have tried to find the solutions, but I can't quite get them to work..