str() for containers

Leif K-Brooks eurleif at
Wed Jun 16 18:56:25 CEST 2004

George Sakkis wrote:
> I find the string representation behaviour of builtin containers
> (tuples,lists,dicts) unintuitive in that they don't call recursively str()
> on their contents (e.g. as in Java) :

They use repr(), not str():

 >>> class Foo(object):
...     def __repr__(self):
...             return 'foo'
 >>> print Foo()
 >>> print [Foo()]

More information about the Python-list mailing list