Overview:
- The Python built-in function repr() returns the string representation of an object.
Example:
The Python code example below prints the string representation for an integer, a floating point number and an object of user defined class Banner. For the Banner object, the representation comes from the __repr__() method implemented in the Banner class.
# Example Python program that prints def display(self): def __repr__(self): # Get info about an int object # Get info about a floating point object # Get info about an instance of an user defined class |
Output:
10 <class 'int'> 10.1 <class 'float'> <type:Banner,id:4401581648,msg:Hello World> |