w3resource

Python Exercise: Print a tuple with string formatting


20. Print 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

For more Practice: Solve these Related Problems:

  • Write a Python program to format and print a tuple within a string using f-strings.
  • Write a Python program to use the format() method to display a tuple inside a sentence.
  • Write a Python program to embed a tuple into a string using old-style % formatting.
  • Write a Python program to create a formatted output where a tuple is displayed as part of a message using concatenation.

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.