Python – Tuple Exercises

Exercise 1: Create a Tuple

Question

Create a tuple of fruits and print it.

Solution

fruits = ("apple", "banana", "orange")
print(fruits)

Exercise 2: Access Tuple Items

Question

Print the first and last item of a tuple.

Solution

nums = (10, 20, 30, 40)

print(nums[0])
print(nums[-1])

Exercise 3: Tuple Length

Question

Find how many items are in a tuple.

Solution

colors = ("red", "blue", "green")
print(len(colors))

Exercise 4: Loop Through Tuple

Question

Print all items using a loop.

Solution

animals = ("cat", "dog", "cow")

for animal in animals:
print(animal)

Exercise 5: Check Item Exists

Question

Check if "banana" is in the tuple.

Solution

fruits = ("apple", "banana", "orange")
print("banana" in fruits)

Exercise 6: Count Item in Tuple

Question

Count how many times 2 appears.

Solution

nums = (1, 2, 2, 3, 2)
print(nums.count(2))

Exercise 7: Find Index of Item

Question

Find the index of "orange".

Solution

fruits = ("apple", "banana", "orange")
print(fruits.index("orange"))

Exercise 8: Unpack Tuple

Question

Unpack tuple values into variables.

Solution

student = ("Amit", 20, "Delhi")

name, age, city = student
print(name)
print(age)
print(city)

Exercise 9: Update Tuple (Trick)

Question

Change "red" to "yellow" in the tuple.

Solution

colors = ("red", "blue", "green")

temp = list(colors)
temp[0] = "yellow"
colors = tuple(temp)

print(colors)

Exercise 10: Add Item to Tuple

Question

Add "grape" to the tuple.

Solution

fruits = ("apple", "banana")

fruits = fruits + ("grape",)
print(fruits)

Exercise 11: Remove Item from Tuple

Question

Remove "dog" from the tuple.

Solution

animals = ("cat", "dog", "cow")

temp = list(animals)
temp.remove("dog")
animals = tuple(temp)

print(animals)

Exercise 12: Join Two Tuples

Question

Join two tuples into one.

Solution

a = (1, 2)
b = (3, 4)

c = a + b
print(c)

Exercise 13: Loop with Index

Question

Print index and value of tuple items.

Solution

colors = ("red", "blue", "green")

for i, value in enumerate(colors):
print(i, value)

Exercise 14: Tuple with One Item

Question

Create a tuple with one value.

Solution

single = ("apple",)
print(type(single))

Exercise 15: Swap Values Using Tuple

Question

Swap two numbers using tuple.

Solution

a = 5
b = 10

a, b = b, a
print(a, b)

✅ Summary

✔ Tuples store fixed data
✔ Tuples cannot be changed directly
✔ Use index to access values
✔ Use count() and index()
✔ Use tricks to update tuple

📘 Perfect for Beginner eBook

This exercise chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • Python Sets (easy)

  • Set Exercises

  • Dictionaries (easy)

  • Dictionary Exercises

Just tell me 😊

You may also like...