Special Method Protocols

__repr__() — object lifecycle protocol

Provide developer-oriented representation for repr() and many container displays. Return a str, ideally unambiguous; it need not be an evaluable expression.

Formal Syntax & Structure

python syntaxpython
def __repr__(self):

Return Value

str

Developer representation.

Working Example

Example Snippetpython
class Ticket:    def __repr__(self): return "Ticket(7)"print(repr(Ticket()))
Python Reference