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.

CategoryBuilt-in Functions
KindBuilt-in Function
Python Versionall

📝 Syntax

repr(object)

⚙️ Parameters

object RequiredThe 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'
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏