how to use __str__ and __repr__?

Peter Hansen peter at
Tue Jun 8 00:25:13 CEST 2004

Jim Newton wrote:

> hi all, does anyone know what print does if there is no __str__ method?

 From the documentation at :

__repr__( self)

Called by the repr() built-in function and by string conversions 
(reverse quotes) to compute the ``official'' string representation of an 
object. .... If a class defines __repr__() but not __str__(), then 
__repr__() is also used when an ``informal'' string representation of 
instances of that class is required.

Does that help?

More information about the Python-list mailing list