class Link:
def __repr__(self):
if self.rest is not Link.empty:
rest_repr = ', ' + repr(self.rest)
else:
rest_repr = ''
return 'Link(' + repr(self.first) + rest_repr + ')'
I wonder :Is the repr function a built-in funciton in Python even though I am defining the __repr__ function?
Answer: the repr() is a bulit-in function. we can use the repr() in the __repr__ function
Look at this piece of code, what do you notice?
Exactly: you are using
repr(self.rest), which is equivalent toself.rest.__repr__().In other words you aren't calling
repron an instance ofLink, but just on an attribute of it. So you aren't callingLink.__repr__into its body, don't worry.