repr() Printable representation
Last updated: 2026-09-22
repr() Printable representation
repr() returns the official string representation; ideally one that could be passed to eval() to rebuild the object.
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
repr(object)
⚙️ Parameters
| object Required | The object to represent. |
|---|
Returns:A string representation of the object; ideally eval()-reconstructible, more debugging-oriented than str().
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
datetime.datetime(2026, 1, 1, 0, 0)
'hello'
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat is the difference between repr() and str()?
Astr() is the human-friendly form (what print uses by default); repr() is the developer-facing 'official representation', meant to be reconstructible via eval(). For example repr('a') is "'a'" (with quotes) while str('a') is a.
QWhy are string elements printed with quotes inside a list?
ABecause print uses repr() for elements inside containers: print(['a']) actually displays the repr form of ["'a'"], making element types easier to distinguish.
QCan repr really reconstruct an object?
AMostly for built-in types — eval(repr(x)) restores them; custom classes must implement __repr__ themselves to make it meaningful, otherwise the default shows the object's memory address.
QHow do I use repr in an f-string?
AUse the conversion flag: f'{x!r}' is equivalent to repr(x); when debugging, !r is often combined to inspect an object's real structure.