Weird list conversion

Chris Angelico rosuav at gmail.com
Sun Dec 13 16:09:45 EST 2015


On Mon, Dec 14, 2015 at 7:31 AM, Erik <python at lucidity.plus.com> wrote:
> On 13/12/15 20:28, Erik wrote:
>>
>> When you call "print", then the list class's __repr__() method is called
>> which in turn calls the contained objects' __repr__() methods in turn
>
>
> I mean the __str__() method, not __repr__() in this case - however, the
> answer is otherwise the same.

It actually makes no difference; lists don't have __str__, and fall
back on object.__str__, which returns self.__repr__(). Inside
list.__repr__, the contained objects' reprs are combined. With lists,
you always get the repr. :)

ChrisA



More information about the Python-list mailing list