Help for Python newbie

Alex Martelli aleaxit at yahoo.com
Tue Jun 12 05:33:14 EDT 2001


"Bob Hibberdine" <bob.hibberdine at ntlworld.com> wrote in message
news:zSkV6.18764$m4.73107 at news6-win.server.ntlworld.com...
    ...
> >>> import string
> >>> mylist = ['1','2','3']
> >>> mystring = ''
> >>> mystring = mystring.join(mylist)
> >>> print mystring
> 123
>
> note there is no space between the items.

Right: the separator is mystring, and mystring is empty,
so the separator is empty.  To use tab as the separator:

>>> mystring = '\t'
>>> mystring = mystring.join(mylist)
>>> print mystring
1    2    3

or, more simply, just:
>>> mystring = '\t'.join(mylist)


Alex






More information about the Python-list mailing list