[Tutor] Str Method

eryksun eryksun at gmail.com
Fri Nov 2 01:43:46 CET 2012


On Thu, Nov 1, 2012 at 8:19 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>
>     s = str(self._theElements)
>     s = s.replace("[", "{").replace("]", "}")
>     return s
>
>
> Another way is to build the string yourself:
>
>     s = ', '.join(str(item) for item in self._theElements)
>     return '{' + s + '}'

Or

    s = str(self._theElements)
    return "{%s}" % s[1:-1]


More information about the Tutor mailing list