expand tuple in string

A

Ansgar Wollnik

Hello all,

I'd like to expand a tuple into a string (to use this for a MySQL-Select).

result=""
tuple=('one','two','three')
for element in tuple:
result=result+","+element

But this doesn't work. What can I do to get a string like this:

result="one, two, three"

Thanks for your help,
Ansgar
 
E

Erik Max Francis

Ansgar said:
I'd like to expand a tuple into a string (to use this for a
MySQL-Select).

result=""
tuple=('one','two','three')
for element in tuple:
result=result+","+element

But this doesn't work. What can I do to get a string like this:

result="one, two, three"

Try:

', '.join(myTuple)
 
M

Mark Day

Ansgar said:
I'd like to expand a tuple into a string (to use this for a MySQL-Select).

result=""
tuple=('one','two','three')
for element in tuple:
result=result+","+element

But this doesn't work. What can I do to get a string like this:

result="one, two, three"

The join method of strings:
'one, two, three'

-Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,167
Messages
2,570,911
Members
47,453
Latest member
MadelinePh

Latest Threads

Top