Home > Software design >  Clean tuple to string
Clean tuple to string

Time:11-15

I have a variable p which print(p) = ('180849', '104735') and I want it to be p = 180849 104735

So, basically get rid off ( and ' and ,

Any help with that please?

CodePudding user response:

You can directly unpack the elements to print function. By default print function insert space between the values(this can be controlled via sep argument)

>>> p = ('180849', '104735')
>>> print(*p)
180849 104735
>>> print(*p, sep='-')
180849-104735

CodePudding user response:

How about this, it is the easier way!

tup = ('this', 'is', 'a', 'tuple')
res = " ".join(tup)

I hope you like it.

  • Related