0 votes
in Python by
Demonstrate how to convert a Tuple to a String in Python.

1 Answer

0 votes
by
In Python, converting a tuple to a string can be achieved using the str() function or the join() method. The str() function converts non-string data types into a string format but it keeps the parentheses and commas of the tuple. Here’s an example:

tuple1 = ('a', 'b', 'c')

str_tuple = str(tuple1)

print(str_tuple)  # Output: "('a', 'b', 'c')"

If you want to convert a tuple of strings without keeping the parentheses and commas, use the join() method:

tuple2 = ('d', 'e', 'f')

str_tuple2 = ''.join(tuple2)

print(str_tuple2)  # Output: "def"

Related questions

0 votes
asked Jan 1, 2021 in Python by SakshiSharma
0 votes
asked Dec 19, 2019 in Python by sharadyadav1986
...