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:
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:
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.
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://www.w3resource.com/python-exercises/tuple/python-tuple-exercise-20.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics