__repr__

__repr__ returns an unambiguous text form of an object for programmers; __str__ returns a friendly one for readers, used by print.

In more detail

Without __repr__, an object shows as something like <Point object at 0x...>, which helps nobody in the shell or a debugger. If you only define one, define __repr__; print falls back to it.

Example

def __repr__(self):
    return f"Point({self.x}, {self.y})"

Related terms

Taught in

References