Write a Python program to print a tuple with string formatting


Sample tuple : ("watermelons", "strawberries", "mangoes", "bananas", "grapefruits", "oranges", "apples", "pears")
Output : Fruits ('watermelons', 'strawberries', 'mangoes', 'bananas', 'grapefruits', 'oranges', 'apples', 'pears')

The program is written in Python and it declares a tuple t with eight string values representing the names of fruits. The program then uses the print function to display the tuple t with the message "Fruits". The format method of the string is used to insert the tuple t into the message. Finally, the program contains a print statement to print the value of the variable dic. However, the variable dic has not been defined in the previous code and this statement will raise a NameError with the message "NameError: name 'dic' is not defined".

Source Code

t = ("watermelons", "strawberries", "mangoes", "bananas", "grapefruits", "oranges", "apples", "pears")
print('Fruits {0}'.format(t))
 
print (dic)
 

Output

Fruits ('watermelons', 'strawberries', 'mangoes', 'bananas', 'grapefruits', 'oranges', 'apples', 'pears')


Example Programs