Definition
The repr() function returns a readable version of an object.
Syntax
repr(obj)
Parameters
Parameter | Description |
---|---|
obj | Required. An object. |
Examples:
myStr = "Python"
print(repr(myStr))
An example overriding the repr() function:
class Car:
name = 'Volvo'
def __repr__(self):
return repr('My car is a ' + self.name )
print(repr(Car()))