alternative display for them as noted in general tools may also prefer __str__ to leave other classes the option of adding an alternative __repr__ display for use in other contextsas long as print and str displays suffice for the tool converselya general tool that codes __repr__ still leaves clients the option of adding alternative displays with __str__ for print and str in other wordsif you code eitherthe other is available for an additional display in cases where the choice isn' clear__str__ is generally preferred for larger user-friendly displaysand __repr__ for lower-level or as-code displays and all-inclusive roles let' write some code to illustrate these two methodsdistinctions in more concrete terms the prior example in this section showed how __repr__ is used as the fallback option in many contexts howeverwhile printing falls back on __repr__ if no __str__ is definedthe inverse is not true--other contextssuch as interactive echoesuse __repr__ only and don' try __str__ at allclass addstr(adder)def __str__(self)return '[value% ]self data __str__ but no __repr__ convert to nice string addstr( default __repr__ print(xruns __str__ [value str( )repr( ('[value ]'''because of this__repr__ may be best if you want single display for all contexts by defining both methodsthoughyou can support different displays in different contexts --for examplean end-user display with __str__and low-level display for programmers to use during development with __repr__ in effect__str__ simply overrides __repr__ for more user-friendly display contextsclass addboth(adder)def __str__(self)return '[value% ]self data def __repr__(self)return 'addboth(% )self data addboth( addboth( print( [value str( )repr( ('[value ]''addboth( )'user-friendly string as-code string runs __repr__ runs __str__ string representation__repr__ and __str__