all Python 3Built-in functionsterm
repr
strings
Returns the official string representation of an object — one the object can be recreated from where possible.
Syntax
repr(object)
Reach for repr when print is hiding something: it shows quotes and escape sequences, so you can tell the string '1' from the number 1 and spot a stray trailing space or newline. Inside containers Python always calls repr on the elements — that is why print(['a']) shows quotes while print('a') does not. For your own classes repr falls back to the useless <Foo object at 0x...> until you define __repr__.
Examples
print(repr('hello')) # → 'hello'
print(repr([1,2,3])) # → [1, 2, 3]
print(repr(None)) # → None
print(repr(3.14)) # → 3.14
print(repr({'a':1})) # → {'a': 1}
See also
Open in the full glossarydocs.python.orgReport an inaccuracy