[Tutor] understanding join

John Fouhy john at fouhy.net
Thu Jul 31 04:57:20 CEST 2008


On 31/07/2008, Steve Poe <steve.poe at gmail.com> wrote:
>  Your explanation is very help. It does make be wonder the usefulness
>  of join with strings. Do you have a practical example/situation?

Kent's example is common: you might have a list of strings that you
want to display to the user, so you call ', '.join() on the list.
Calling ''.join() is the standard way in Python to concatenate a bunch
of strings.  If you've got some two-dimensional data structure that
you want to convert to CSV, you could use the csv module, but if your
data is simple, it might be easier to just do: '\n'.join(','.join(row)
for row in data)

I guess it depends what kind of programming you're doing, but in my
experience, .join() is definitely a useful function.

-- 
John.


More information about the Tutor mailing list