w3resource

Python Exercise: Print a tuple with string formatting

Python tuple: Exercise-20 with Solution

Write a Python program to print a tuple with string formatting.

Pictorial Presentation:

Python Tuple: Print a tuple with string formatting.

Sample Solution:

Python Code:

# Create a tuple containing three numbers
t = (100, 200, 300)

# Use the 'format' method to insert the tuple 't' into the string and print the result
print('This is a tuple {0}'.format(t))

Sample Output:

This is a tuple (100, 200, 300) 

Flowchart:

Flowchart: Print a tuple with string formatting

Python Code Editor:

Previous: Write a Python program to convert a list of tuples into a dictionary.
Next: Write a Python program to replace last value of tuples in a list.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-exercises/tuple/python-tuple-exercise-20.php