On this page
repr
Prev: range | Up: __builtins__ | Next: reversed
Rel: callable, delattr, dir, getattr, hasattr
Ref: docs.python.org — repr
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import repr
Overview & Signature
repr(obj, /)
Return the canonical string representation of the object.
Usage
assert repr("hi\n") == "'hi\\n'"
assert str("hi\n") == "hi\n"
Gotchas
- Developer/debugging representation:
repr()shows quotes and escapes (f"{x!r}"in f-strings), whilestr()is for end-user display.
REPL Inspect
help(repr)
Linked from
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/range Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/reversed Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/callable Linked here; shared tags: #builtins
- tuts/python3/__builtins__/delattr Linked here; shared tags: #builtins
- tuts/python3/__builtins__/dir Linked here; shared tags: #builtins
- tuts/python3/__builtins__/getattr Linked here; shared tags: #builtins
- tuts/python3/__builtins__/hasattr Linked here; shared tags: #builtins
- tuts/c/builtins shared tags: #builtins