[Tutor] Making String
Steven D'Aprano
steve at pearwood.info
Wed Aug 11 00:22:29 CEST 2010
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
More information about the Tutor
mailing list