__repr__
Dunder MethodPython 2.0+Intermediate
Returns an unambiguous developer-facing string representation
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
class Point: def __init__(self, x, y): self.x = x self.y = y def __repr__(self): return f"Point({self.x}, {self.y})" p = Point(3, 4) print(repr(p)) print(p) # Falls back to __repr__ if no __str__
__repr__ returns an unambiguous developer-facing string representation. Implementing it lets you customize how Python interacts with your objects.
Try in PlaygroundTags
oopmagic-methodprotocolcore