Given a tuple of characters, Write a python program to convert the tuple into a string.
Examples:
Input : ('a', 'b', 'c', 'd', 'e')
Output : abcde
Input : ('g', 'e', 'e', 'k', 's')
Output : geeks
Approach
There are various approaches to convert a tuple to a string.
- Approach 1 : using str.join()
The join() method is a string method and returns a string in which the elements of sequence have been joined by str separator.
Using join() we add the characters of the tuple and convert it into string.# Python3 code to convert tuple# into stringdefconvertTuple(tup):str=''.join(tup)returnstr# Driver codetuple=('g','e','e','k','s')str=convertTuple(tuple)print(str)chevron_rightfilter_noneOutput:
geeks
- Approach 2 : using reduce() function
The reduce(fun, seq) function is used to apply a particular function passed in its argument to all of the list elements mentioned in the sequence passed along. We pass the add operator in the function to concatenate the characters of tuple.# Python3 code to convert tuple# into stringimportfunctoolsimportoperatordefconvertTuple(tup):str=functools.reduce(operator.add, (tup))returnstr# Driver codetuple=('g','e','e','k','s')str=convertTuple(tuple)print(str)chevron_rightfilter_noneOutput:geeks
- Python program to convert Set into Tuple and Tuple into Set
- Python - Convert Tuple String to Integer Tuple
- Python - Convert Tuple to Tuple Pair
- Python - Convert Tuple Matrix to Tuple List
- Python | Sort tuple list by Nth element of tuple
- Python | Replace tuple according to Nth tuple element
- Python - Raise elements of tuple as power to another tuple
- Python - Flatten tuple of List to tuple
- Python program to convert a list of strings with a delimiter to a list of tuple
- Python | Convert String to tuple list
- Python | Convert tuple records to single string
- Python | Convert String to Tuple
- Python | Convert String to N chunks tuple
- Python | Convert mixed data types tuple list to string list
- Python | Convert a list into a tuple
- Python | Convert a list into tuple of lists
- Python | Convert list of tuple into dictionary
- Python | Convert list to indexed tuple list
- Python | Convert location coordinates to tuple
- Python | Convert Integral list to tuple list
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

