class A(object):
def __init__(self):
self.lang = "python"
def __repr__(self):
return "<{} lang={}>".format(self.__class__.__name__, self.lang)
def __str__(self):
return "<{} language={}>".format(self.__class__.__name__, self.lang)
if __name__ == '__main__':
a = A()
b = repr(a)
c = str(a)
print("{:<50} {}".format(a, type(a)))
print("{:<50} {}".format(b, type(b)))
print("{:<50} {}".format(c, type(c)))
# output
# <A language=python> <class '__main__.A'>
# <A lang=python> <type 'str'>
# <A language=python> <type 'str'>
网友评论