What is the repr() function in Python?

Overview

In Python, we use the repr() function to return a string that contains a printable representation of an object.

Syntax

repr(object)

Parameters

As a parameter, this method takes the object whose printable representation is required.

Return value

This method returns a string.

Code example

print(repr(5))
print(type(repr(5)))
print(repr(5.5))
print(type(repr(5.5)))
print(repr(False))
print(type(repr(False)))
print(repr(7+2))
print(type(repr(7+2)))

When we pass the printable representation of an object to eval(), we get the original object in return.

The code example given below explains this:

myString = "2 + 3"
print(eval(repr(myString)))
print(type(repr(myString)))

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved