Python Program to Convert Tuple to String

Write a Python program to Convert Tuple to String. We used the string join function to join or convert the tuple Items.

strTuple = ('p', 'y', 't', 'h', 'o', 'n')
print("Tuple Items = ", strTuple)

stringVal = ''.join(strTuple)
print("String from Tuple = ", stringVal)
Tuple Items =  ('p', 'y', 't', 'h', 'o', 'n')
String from Tuple =  python

Python Program to Convert Tuple to String using for loop

In this Python Tuple to String example, we used the for loop (for t in strTuple) and for loop range (for i in range(len(strTuple))) to iterate the tuple items. Within the loop, we are concatenating each tuple item to a declared string.

strTuple = ('t', 'u', 't', 'o', 'r', 'i', 'a', 'l')
print("Tuple Items = ", strTuple)

strVal = ''
for t in strTuple:
    strVal = strVal + t
    
print("String from Tuple = ", strVal)

stringVal = ''
for i in range(len(strTuple)):
    stringVal = stringVal + strTuple[i]
    
print("String from Tuple = ", stringVal)
Tuple Items =  ('t', 'u', 't', 'o', 'r', 'i', 'a', 'l')
String from Tuple =  tutorial
String from Tuple =  tutorial

This example uses the lambda function to convert the tuple items to string.

from functools import reduce

strTuple = ('t', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's')
print("Tuple Items = ", strTuple)

strVal = reduce(lambda x, y: str(x) + str(y), strTuple, '')
print("String from Tuple = ", strVal)
Python Program to Convert Tuple To String 3

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.