string – python: cannot concatenate str and tuple objects (it should works!)

string – python: cannot concatenate str and tuple objects (it should works!)

print tuple(something)

may work because print will do an implicit str() on the argument, but and expression like

 + ()

does not work. The fact that you can print them individually doesnt make a difference, you cant concatenate a string and a tuple, you have to convert either one of them. I.e.

print foo + str(tuple(bar))

However, depending on str() for conversion probably wont give the desired results. Join them neatly using a separator using ,.join for example

Why do you think it should work?

try:

print bug tuple  + str(tuple(temp.split(, )))

string – python: cannot concatenate str and tuple objects (it should works!)

Change it to

print bug tuple , tuple(temp.split(, ))

Leave a Reply

Your email address will not be published.