self data +other adder(print(xx add other in place (bad form?default displays but coding or inheriting string representation methods allows us to customize the display--as in the followingwhich defines __repr__ method in subclass that returns string representation for its instances class addrepr(adder)def __repr__(self)return 'addrepr(% )self data inherit __init____add__ add string representation convert to as-code string addrepr( addrepr( print(xaddrepr( str( )repr( ('addrepr( )''addrepr( )'runs __init__ runs __add__ ( add(better?runs __repr__ runs __repr__ runs __repr__ for both if defined__repr__ (or its close relative__str__is called automatically when class instances are printed or converted to strings these methods allow you to define better display format for your objects than the default instance display here__repr__ uses basic string formatting to convert the managed self data object to more humanfriendly string for display why two display methodsso farwhat we've seen is largely review but while these methods are generally straightforward to usetheir roles and behavior have some subtle implications both for design and coding in particularpython provides two display methods to support alternative displays for different audiences__str__ is tried first for the print operation and the str built-in function (the internal equivalent of which print runsit generally should return user-friendly display __repr__ is used in all other contextsfor interactive echoesthe repr functionand nested appearancesas well as by print and str if no __str__ is present it should generally return an as-code string that could be used to re-create the objector detailed display for developers that is__repr__ is used everywhereexcept by print and str when __str__ is defined this means you can code __repr__ to define single display format used everywhere operator overloading