w3resource

Python Exercise: Print a tuple with string formatting


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.



Follow us on Facebook and Twitter for latest update.