__repr__ should return a printable representation of the object, most likely one of the ways possible to create this object. See also documentation for repr() (which calls __repr__). __repr__ is more for developers, while __str__ is for end users.

A simple example (interactive):

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def __repr__(self):
        cls = self.__class__.__name__
        return f'{cls}(x={self.x!r}, y={self.y!r})'
p = Point(1, 2)
p

Output:

Point(x=1, y=2)
Answer from Miki Tebeka on Stack Overflow
🌐
Codecademy
codecademy.com › docs › python › dunder methods › __repr__()
Python | Dunder Methods | __repr__() | Codecademy
May 20, 2025 - The __repr__() method is a special method in Python that returns a string representation of an object. This method is one of Python’s dunder (double underscore) methods that provides an “official” string representation of an object.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › repr.html
repr — Python Reference (The Right Way) 0.1 documentation
For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(), otherwise the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a __repr__() method.
🌐
Scaler
scaler.com › home › topics › what is python __repr__?
What is Python __repr__? | Scaler Topics
May 4, 2023 - If one prints an instance or passes it to format as in str.format, if an \_\_str__ method has been defined, it will be called, otherwise, it will be \_\_repr__ that gets used. The \_\_repr__ function is called by the built-in repr function and is what is “echoed” onto one’s Python shell screen when evaluating an expression that returns an object.
🌐
Codecademy
codecademy.com › docs › python › built-in functions › repr()
Python | Built-in Functions | repr() | Codecademy
June 2, 2023 - A class can control what this function returns for its instances when called by defining a __repr__() dunder method. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
🌐
Python
docs.python.org › 3 › library › reprlib.html
reprlib — Alternate repr() implementation — Python 3.14.7 documentation
Class which provides formatting services useful in implementing functions similar to the built-in repr(); size limits for different object types are added to avoid the generation of representations which are excessively long.
🌐
Real Python
realpython.com › ref › builtin-functions › repr
repr() | Python’s Built-in Functions – Real Python
The .__repr__() method allows instances of the Book class to provide a detailed and developer-friendly string representation, which is useful for debugging and logging. ... Find out when to choose Python's __repr__() vs __str__() in your classes ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-str-repr-functions
How To Use the __str__() and __repr__() Methods in Python | DigitalOcean
Learn Python’s str() and repr() methods in depth. Explore examples, best practices, and real-world tips for clarity and debugging.
Find elsewhere
🌐
O'Reilly
oreilly.com › library › view › mastering-object-oriented-python › 9781789531367 › 4c65b811-c017-4725-bd24-a35cc3e2565e.xhtml
The __repr__() and __str__() methods - Mastering Object-Oriented Python - Second Edition [Book]
June 14, 2019 - The repr() method representation is often more technical, and typically uses a complete Python expression to rebuild an object. The documentation for the __repr__() method in the Python documentation (https://docs.python.org/3/reference/datamodel.html?highlight=__del__#object.__repr__) states the following:
Author: Steven F. Lott
Published: 2019
Pages: 770
🌐
Educative
educative.io › answers › what-is-the-repr-method-in-python
What is the __repr__ method in Python?
They start and end with double underscores. According to the official documentation, __repr__ is used to compute the “official” string representation of an object and is typically used for debugging.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-__repr__-magic-method
Python __repr__() magic method - GeeksforGeeks
July 23, 2025 - In this example, we define a subclass of tuple called MyTuple that overrides the __str__() and __repr__() methods. When we call Python str() or Python repr() on an instance of MyTuple, the custom __str__() and __repr__() methods are called, respectively.
🌐
DataFlair
data-flair.training › blogs › python-repr-function
Python repr Function With Example | repr vs str in Python - DataFlair
April 14, 2026 - Any string at the interpreter prompt makes a call to __str__(), but an object at the prompt makes a call to __repr__(). Want to do preparation for Python Interview – Click Here >>>
🌐
Python
docs.python.org › 3.4 › library › reprlib.html
8.12. reprlib — Alternate repr() implementation — Python 3.4.10 documentation
June 16, 2019 - Class which provides formatting services useful in implementing functions similar to the built-in repr(); size limits for different object types are added to avoid the generation of representations which are excessively long.
🌐
Initial Commit
initialcommit.com › blog › repr-in-python
__repr__ in Python - Initial Commit
The difference is that string will typically print out the contents of a string or other Python object in a human readable format. On the other hand, the repr() function prints out the "string representation" of an object, which usually includes quotes surrounding it.
🌐
Python Pool
pythonpool.com › home › tutorials › python repr(): __repr__, debugging, and string representations
Python repr(): __repr__, Debugging, and String Representations
July 13, 2026 - The official repr() documentation and object.__repr__ data model reference define the representation protocol. Related guidance includes logging and Python data types.
🌐
TutorialsPoint
tutorialspoint.com › What-does-the-repr-function-do-in-Python-Object-Oriented-Programming
Python repr() Function
June 15, 2020 - This function takes an object 'x' as a parameter for which you want to obtain the string representation. This function returns a string that, when executed as Python code, would recreate the original object.
🌐
Python
docs.python.org › 3.8 › library › reprlib.html
reprlib — Alternate repr() implementation — Python 3.8.20 documentation
Changing the attributes of this object will affect the size limits used by repr() and the Python debugger.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-repr-function
Python repr() Function - GeeksforGeeks
July 23, 2025 - Return Type: repr() function returns a string (str) representation of the given object (<class 'str'>).
🌐
BelieveMy
believemy.com › python glossary › __repr__
What is __repr__ in Python? | Python glossary
February 9, 2026 - If you use dataclass or namedtuple, the __repr__ method is automatically generated, saving you from writing it manually. ... When Python displays the content of a container (list, dict, tuple, etc.), it uses __repr__ and not __str__ for each element. This design choice is explained by the fact that displaying a container is generally intended for debugging, and Python therefore favors the unambiguous representation.