Home / Python / Reference / Built-in functions

Python repr() function

Return a precise text form of a value, as you would type it in code.

Syntax

repr(obj)

Shows quotes around strings and hidden characters such as new lines and tabs, which makes it great for debugging. The !r format in an f-string does the same.

Parameters

objany value

Return value

str

Example

Code

s = "tab\there\n"
print(s)
print(repr(s))
print(repr("42"), repr(42))
print(f"{s!r}")

Output

tab	here

'tab\there\n'
'42' 42
'tab\there\n'

Related

Learn it step by step in the free lesson Strings, with exercises that check your answers.