Let's say I have the following class:
class Human(object):
def __init__(self, name, last_name):
self.name = name
self.last_name = last_name
def get_last_name(self):
return self.last_name
And I know I can define a __repr__ method for it:
def __repr__(self):
return "Human being, named " + str(self.name) + " " + str (self.last_name)
However, what if I want to define a separate representation for a lastname method, too? I.e., if this is a sample:
>>> me = Human("Jane", "Doe")
>>> me
Human being, named Jane Doe
>>> me.get_last_name()
'Doe'
…then I want the last output be not only the string 'Doe' itself but something like Human being's last name is Doe – how can it be done? How to define a __repr__ (or a __str__) method for a method?
Thanks.