[Tutor] Making String

Joel Goldstick joel.goldstick at gmail.com
Wed Aug 11 13:56:37 CEST 2010


On Tue, Aug 10, 2010 at 6:22 PM, Steven D'Aprano <steve at pearwood.info>wrote:

> On Wed, 11 Aug 2010 06:09:28 am Joel Goldstick wrote:
> > The str part of str.join() is the string where the result is stored,
> > so you can start off with an empty string: ""
>
> I don't understand what you mean by that. I can only imagine you think
> that the string part is a fixed-width buffer that has the result stored
> into it, but of course that's ridiculous because that's nothing like
> what join does. Python strings are immutable so you can't store
> something inside an existing string, but even if they weren't, since
> the result of join is usually larger than the initial string you pass,
> what would be the point?
>
> The string part of str.join is the string which is used to join the rest
> of the arguments. This:
>
> "spam".join([ "a", "b", "c" ])
>
> is equivalent to:
>
> "a" + "spam" + "b" + "spam" + "c"
>
> except more efficient and faster. The result is stored in a new string.
>
>
>
> --
> Steven D'Aprano
>
> Steve, thanks for correcting me. The str being the 'glue' that joins
between each of the list members.
-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100811/14226d1e/attachment.html>


More information about the Tutor mailing list