[Tutor] a little loop

Andreas Perstinger andipersti at gmail.com
Wed May 29 07:33:16 CEST 2013


On 29.05.2013 05:20, Jim Mooney wrote:
> On 28 May 2013 19:34, Steven D'Aprano <steve at pearwood.info> wrote:
>
> The standard method for assembling a string from a collection
>> of substrings is to do it in one go, using the join method,
>
> Wow, that means I can do this:   print  ''.join('But this parrot is dead!')

But why do you want to do that?

"join" iterates over the string you gave as an argument and puts the 
empty string in between each character:
'B' + '' + 'u' + '' + 't' + '' + ...

Thus you end up with the same string as you started.

Or did you mean something like:

 >>> print '<>'.join('But this parrot is dead!')
B<>u<>t<> <>t<>h<>i<>s<> <>p<>a<>r<>r<>o<>t<> <>i<>s<> <>d<>e<>a<>d<>!

Bye, Andreas


More information about the Tutor mailing list