擅长:python、mysql、java
<p><code>__repr__</code>应该返回对象的可打印表示,很可能是创建此对象的方法之一。见官方文件<a href="http://docs.python.org/library/functions.html#repr" rel="noreferrer">here</a>。<code>__repr__</code>更适合开发人员,而<code>__str__</code>则适合最终用户。</p>
<p>一个简单的例子:</p>
<pre><code>>>> class Point:
... def __init__(self, x, y):
... self.x, self.y = x, y
... def __repr__(self):
... return 'Point(x=%s, y=%s)' % (self.x, self.y)
>>> p = Point(1, 2)
>>> p
Point(x=1, y=2)
</code></pre>