The repr()
function in Python returns a string representation of the object. It is called by the repr()
built-in function and by the backquote operator. The returned string is intended for debugging or informative purposes and should generally produce a string that, when passed to eval(), will re-create the same object.
Parameter Values
Parameter | Description |
---|---|
object | The object whose |
Return Values
The repr()
function returns a string representing the object.
How to Use repr()
in Python
Example 1:
The repr()
function returns a string representation of the object. This is typically used for debugging or logging purposes to provide a more detailed representation of the object.
class Example:
def __init__(self):
pass
def __repr__(self):
return 'Example class'
obj = Example()
print(repr(obj))
# Output: Example class