[Tutor] Noob question
amitsaxena69 at gmail.com
Mon Dec 10 14:19:19 CET 2007
The simplest way i could think of:
b = ""
for i in range(len(a)):
b += a[i]
On Dec 10, 2007 6:48 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "Eric Walstad" <eric at ericwalstad.com> wrote
> > You could also achieve the same result of concatenating a list of
> > strings by looping over the list items like so:
> > b = ''
> > for fruit in a:
> > b += fruit
> > print b
> And to add to the options you could use the formatting operator
> provided you know there are only 3 items,
> b = "%s%s%s" % tuple(a)
> Or for an indefinite number of strings:
> b = "%s" * len(a)
> b = b % tuple(a)
> So many options. However, to the OP, if you get stuck in
> future its best if you post the erroneous code that you have tried,
> then we can better see where you have gone wrong and thus
> provide clearer guidance on how to fix it. Its better to learn to
> do it your own way correctly than just to see other folks
> attempts .
> Alan Gauld
> Author of the Learn to Program web site
> Tutor maillist - Tutor at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor