w3resource

Python Exercise: Tuple to a string


6. Convert a Tuple to a String

Write a Python program to convert a tuple to a string.

Pictorial Presentation:

Python Tuple: Tuple to a string.

Sample Solution:

Python Code:

# Create a tuple containing individual characters
tup = ('e', 'x', 'e', 'r', 'c', 'i', 's', 'e', 's')
# Use the 'join' method to concatenate the characters in the tuple without any spaces and create a single string
str = ''.join(tup)
# Print the resulting string
print(str)

Sample Output:

exercises 

Flowchart:

Flowchart: Get an item of a tuple

For more Practice: Solve these Related Problems:

  • Write a Python program to convert a tuple of characters into a string using the join() method.
  • Write a Python program to implement a function that takes a tuple of words and returns a concatenated sentence.
  • Write a Python program to convert a tuple of numbers into a string where each number is separated by a dash.
  • Write a Python program to iterate over a tuple and construct a string using string concatenation.

Python Code Editor:

Previous: Write a Python program to add an item in a tuple.
Next: Write a Python program to get the 4th element and 4th element from last of a tuple.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.