Convert Tuple to String in Python

  • Post category:String

You can use the join() function to convert a tuple to string. The join() function can take a tuple as input and return a string. Let’s code an example to convert a tuple to a string.

Step 1: Create a tuple of strings

tpl =  ('C', 'o', 'd', 'e', 'A', 'l', 'l', 'o', 'w')
print("tuple = ", tpl)
print("tuple type = ", type(tpl))

Step 2: Convert tuple to string

str = ''.join(tpl)
print("str = ", str)
print("str type = ", type(str))

Output:

tuple =  ('C', 'o', 'd', 'e', 'A', 'l', 'l', 'o', 'w')
tuple type =  <class 'tuple'>
str =  CodeAllow
str type =  <class 'str'>

Free resources to learn advanced skills: AiHints and CodeAllow