AI engineering glossary · Python advanced

What is __repr__?

__repr__: The special method returning an unambiguous text form of an object, intended for developers and debugging. It is used by the interactive prompt and by print for containers. Ideally it looks like code that could recreate the object.

Level: intermediateTopic: Python advanced

__repr__: an example

def __repr__(self): return f'Point({self.x}, {self.y})' makes a point display as Point(3, 4) in a list.

Related terms

More Python advanced terms

Where you learn it

__repr__ is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.