[Python] __repr__ vs repr [duplicate]

Discussão em 'Python' iniciado por Stack, Agosto 7, 2025.

  1. Stack

    Stack Membro Participativo

    Is there a difference between the two methods?

    For example,

    >>> from datetime import date
    >>> today = date(2012, 10, 13)
    >>> repr(today)
    'datetime.date(2012, 10, 13)'
    >>> today.__repr__()
    'datetime.date(2012, 10, 13)'


    They seem to do the same thing, but why would someone want to use the latter over the regular repr?

    Continue reading...

Compartilhe esta Página