Contents
Convert Tuple to String in Python
When we say that we convert tuple into a string, we mean that we shall append all the items and form a single string.
In this tutorial, we will learn how to convert a tuple to a string.
There are many ways to realize this conversion of tuple to string. We shall discuss the following of them.
- Use string.join() method.
- Use For loop statement
Examples
1. Convert a tuple into a 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.
Python Program
tuple1 = ('p', 'y', 't', 'h', 'o', 'n')
# Tuple to string
str = ''.join(tuple1)
print(str)
Run Code CopyOutput
python
2. Convert a tuple into a 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.
Python Program
tuple1 = ('p', 'y', 't', 'h', 'o', 'n')
str = ''
for item in tuple1:
str = str + item
print(str)
Run Code CopyOutput
python
Summary
In this tutorial of Python Examples, we learned how to convert a Python Tuple into a String, with the help of well detailed examples.