理解"__repr__"

class aTest:

    def __repr__(self):
        return "This is an aTest class."

a = aTest()
print (a)

class bTest:
    pass

b = bTest()
print(b)

输出结果:

This is an aTest class.
<__main__.bTest object at 0x102a7f8d0>

所以,__repr__决定了直接打印一个实例时输出的字符串。

原文地址:https://www.cnblogs.com/yaos/p/14014291.html