Convert Tuple to String in Python
In this tutorial, we will learn how to convert a tuple to a string.
When we say that we convert tuple into a string, we mean that we shall append all the items and form a single string.
There are many ways to realize this conversion of tuple to string. We shall discuss the following of them.
- Use string.join() method.
Example 1: Convert Tuple to String using join()
In this example, we shall take a tuple and use join() method to append all the items of a tuple and form a string.
tuple1 = ('p', 'y', 't', 'h', 'o', 'n') #tuple to string str = ''.join(tuple1) print(str)
Example 2: Convert Tuple to String using For Loop
You may also use Python For Loop to iterate over the items of tuple and append them to a String.
In this example, we shall take a tuple and an empty string, and iterate over the tuple. For each item in tuple, append the item to the string.
tuple1 = ('p', 'y', 't', 'h', 'o', 'n') str = '' for item in tuple1: str = str + item print(str)
In this tutorial of Python Examples, we learned how to convert a Python Tuple into a String, with the help of well detailed examples.