repr()
The repr()
function returns a printable string describing the object that is passed in. In other words, it returns the string representation passed implicitly to the eval()
function.
A class can control what this function returns for its instances when called by defining a __repr__()
dunder method.
Syntax
The repr()
function accepts a single object as parameter.
repr(object)
Codebyte Example
Below, two instances of repr()
are called:
- The first one returns the default value (a string with the name and address of the object, enclosed in angle brackets).
- The second defines the output string and implements the
__repr__()
method.
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.