I'm creating a class that prints out its contents using the str() function. However, I can only seem to be able to get it to print out one of the parameters? When I ask it to return self.num as well as self.word it throws an error.
Would anyone be able to help me on this?
class Test:
def __init__ (self, word, num):
self.word = word
self.num = num
def __str__(self):
return self.word, self.num
a = Test('Word', '10')
print(a)
__str__must return a str; it cannot return a tuple. You'll have to create a string of them first.