English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The repr() function returns the printable representation form of the given object.
The syntax of repr() is:
repr(obj)
repr() function takes a single parameter:
obj -Must return the object in its printable representation form
The repr() function returns a printable string representation of the given object.
var = 'foo' print(repr(var))
Output result
"'foo'"
Here, we providevarAssign a value 'foo'. Then, the repr() function returns "'foo'", with 'foo' inside the double quotes.
When the result of repr() is passed to eval(), we will obtain the original object (for many types).
>>> eval(repr(var)) 'foo'
Internally, the repr() function calls the given object's __repr__().
You can easily implement/Rewriting __repr__() and the different ways repr() works.
class Person: name = 'Adam' def __repr__(self): return repr('Hello ' + self.name ) print(repr(Person()))