Write a Python Program to print the list of total items in a tuple. We can use the print function to print the whole tuple. In this example, we declared string and int tuples and prints them.
# Print Tuple Items numTuple = (10, 20, 30, 40, 50) print("The Tuple Items are ") print(numTuple ) strTuple = ('C#', 'Java', 'Python', 'C') print("\nThe String Tuple Items are ") print(strTuple )
In this Python Program, we use for loop range to access each tuple item. The first for loop iterate from the first tuple item to the last and print each element. And the second loop prints all the fruits in the string tuple.
# Print Tuple Items numTuple = (10, 20, 30, 40, 50) print("The Tuple Items are ") for i in range(len(numTuple)): print("Tuple Item at %d Position = %d" %(i, numTuple[i])) print("=========") fruitsTuple = ('apple', 'orange', 'kiwi', 'grape') for fruit in fruitsTuple: print(fruit)