Python · Python Collections

Tuples — Practice Questions

50 questions. Try each one yourself before checking the answer.

Q1Creating TuplesEasy

Create point = (3, 4) and print it along with its type().

Q2IndexingEasy

Using colors = ("red", "green", "blue"), print the first and last items.

Q3SlicingEasy

Using numbers = (10, 20, 30, 40, 50), print the first three elements using slicing.

Q4len()Easy

Print the number of items in weekdays = ("Mon", "Tue", "Wed", "Thu", "Fri").

Q5ImmutabilityEasy

Create point = (3, 4) and try point[0] = 5. Print the error type this raises, in a comment.

Q6PackingEasy

Assign the values 1, 2, 3 to a single variable numbers without parentheses (tuple packing), then print it and its type.

Q7UnpackingEasy

Given point = (3, 4), unpack it into x and y, then print both.

Q8forEasy

Given rgb = (255, 0, 128), print each value using a for loop.

Q9Single-Element TuplesEasy

Create a tuple with a single element 5 (remember the trailing comma) and print its type to confirm it's really a tuple.

Q10MembershipEasy

Given days_off = ("Saturday", "Sunday"), print whether "Monday" is in it.

Q11Tuple MethodsMedium

Given numbers = (4, 8, 2, 8, 5, 8), print how many times 8 appears using .count(), and the index of its first appearance using .index().

Q12Nested TuplesMedium

Create student = ("Asha", (85, 90, 78)). Print the student's name and their second score.

Q13ConcatenationMedium

Given tuple1 = (1, 2, 3) and tuple2 = (4, 5, 6), create a new combined tuple using +, and a repeated tuple using *.

Q14Tuple vs ListMedium

Convert numbers_tuple = (3, 1, 2) into a list, sort it, then convert it back into a tuple. Print the final result.

Q15UnpackingMedium

Given point = (10, 20, 30), unpack it using the "star" syntax so the first value goes to x and the rest go to a list rest.

Q16SwappingMedium

Swap the values of a = 5 and b = 10 using tuple packing/unpacking (revisit from Operators, now naming the mechanism).

Q17Functions & TuplesMedium

Write a function min_max(numbers) that returns a tuple (minimum, maximum), then unpack the result when calling it.

Q18List of TuplesMedium

Given points = [(1, 2), (3, 4), (5, 6)], print each point's x and y separately by unpacking inside a for loop.

Q19sorted() with TuplesMedium

Given people = [("Alice", 30), ("Bob", 25), ("Carol", 35)], sort by age using sorted() with a lambda key.

Q20Tuple ComparisonMedium

Print the results of comparing (1, 2, 3) == (1, 2, 3), (1, 2, 3) < (1, 2, 4), and (1, 3) > (1, 2, 100), and explain in a comment how tuple comparison works.

Q21Real-WorldMedium

Ask the user for two numbers representing coordinates, store them as a tuple point, and print the Euclidean distance from the origin (0, 0).

Q22Real-WorldMedium

Store a color as rgb = (200, 100, 50). Print whether the color is "dominant red" (its first component is the largest of the three).

Q23Real-WorldMedium

Given records = [("Alice", 88), ("Bob", 45), ("Carol", 92)], print each name with "Pass"/"Fail" based on a 40-point threshold, unpacking each record in the loop.

Q24Real-WorldMedium

Ask the user for a month and day and pack them into a date_tuple. Print it formatted as MM/DD.

Q25zip()Medium

Given names = ["Alice", "Bob"] and ages = [30, 25], use zip() to build a list of (name, age) tuples, and print it.

Q26UnzippingMedium

Given pairs = [("Alice", 30), ("Bob", 25)], split it back into two separate lists (names, ages) using zip(*pairs).

Q27Tuple vs ListMedium

Write two short functions, sum_list(numbers) and sum_tuple(numbers), that both compute a sum with a loop, showing that the same logic works on either type since both are iterable.

Q28Real-WorldMedium

Given login_attempt = ("admin", "wrongpass") representing (username, password), unpack it and print whether it matches the correct credentials ("admin", "admin123").

Q29DebuggingMedium

The following code crashes with a TypeError. Find and fix the bug (without converting the tuple to a list).

scores = (85, 90, 78)
scores[0] += 5
print(scores)
Q30FormattingMedium

Given point = (12.5, -3.2), print it formatted as "(12.50, -3.20)" using an f-string with unpacking.

Q31Nested UnpackingHard

Given record = ("Asha", (1995, 6, 15)) representing (name, (birth_year, birth_month, birth_day)), unpack all four values in a single statement.

Q32Multiple AssignmentHard

Given three variables a = 1, b = 2, c = 3, rotate their values in ONE line so that a gets b's value, b gets c's value, and c gets a's original value.

Q33AlgorithmicHard

Given data = [(3, "c"), (1, "a"), (2, "b")], sort it by the first element of each tuple, then print only the second elements in that new order.

Q34Tuple ApplicationsHard

Demonstrate that tuples can be used as dictionary keys while lists cannot, using a small example that maps (row, col) coordinate tuples to values.

Q35Named TuplesHard

Use collections.namedtuple to create a Point type with fields x and y, create an instance, and print both its field access styles: point.x and point[0].

Q36AlgorithmicHard

Given intervals = [(1, 3), (2, 6), (8, 10), (15, 18)], merge any overlapping intervals and print the merged result. (Sort first, then walk through with a loop.)

Q37Tuple ApplicationsHard

Given transactions = [("deposit", 500), ("withdraw", 200), ("deposit", 100)], compute the final balance starting from 1000, unpacking each transaction in a loop.

Q38ImmutabilityHard

Given data = (1, 2, [3, 4]), demonstrate that while the TUPLE itself is immutable, a MUTABLE object stored inside it (the list) can still be changed in place.

Q39AlgorithmicHard

Given pairs = [(1, "a"), (2, "b"), (3, "c")], build a "reversed" list where each tuple's elements are swapped, using a loop and unpacking (not a comprehension).

Q40Tuple vs ListHard

Given a function that should return a fixed 3-value record (name, age, is_active), explain and demonstrate why a tuple is a more appropriate return type here than a list.

Q41Mini-ProjectMini-Project

Build a "Student Record System" using a list of (name, grade) tuples. Support printing all records and finding the highest-graded student, all via unpacking.

Q42Mini-ProjectMini-Project

Build a "Coordinate Distance Calculator". Ask for two points as coordinate pairs and print the distance between them using tuple unpacking.

Q43Mini-ProjectMini-Project

Build an "RGB Color Mixer". Ask for two RGB tuples and print their average color (component-wise), rounded to whole numbers.

Q44Mini-ProjectMini-Project

Build a small "Contact Database" using a list of (name, phone, email) tuples, with a search function that finds a contact by name.

Q45Mini-ProjectMini-Project

Build a "Time Duration Formatter" that takes a total number of seconds and returns a tuple (hours, minutes, seconds), then prints it formatted as HH:MM:SS.

Q46InterviewInterview

A common interview question: "when would you use a tuple instead of a list?" Answer it with two concrete code examples — one where a fixed-shape return value benefits from a tuple, and one where a growing collection clearly needs a list.

Q47InterviewInterview

Explain why tuples are hashable (and therefore usable as dict keys / set members) while lists are not, and demonstrate the TypeError that results from trying to put a list in a set.

Q48InterviewInterview

Demonstrate how tuple unpacking makes function calls that return multiple values more readable than manually indexing into a returned collection, comparing both styles side by side.

Q49InterviewInterview

Explain in a comment why tuples are generally slightly faster to create and iterate over than lists, and demonstrate that a tuple literal is still valid even without wrapping parentheses in specific contexts (like a return statement).

Q50CapstoneInterview

Build a "Tuple Mastery Report" — the most complete demonstration in this module. Given records = [("Alice", 88), ("Bob", 45), ("Carol", 92), ("David", 67)], print: all records unpacked in a formatted table, the record with the highest score, the average score (manual loop), and a new list of (name, "Pass"/"Fail") tuples built without comprehensions.

Still stuck on something?

Book a free 1-on-1 session and we'll work through it together.

Book a Free Session