Kit Library / Computer Science / Programming Fundamentals

⚡ Topic Learning Kit

Tuples in python

English 19 leveled MCQs 18 flashcards Free

Shared by a Veda learner · Generated with Veda AI

Veda Bites

The whole idea, one bite at a time

Veda Bites are swipeable micro-lessons — each one teaches exactly one idea. The bites below come from this kit — swipe through them in the app.

💡 Key Idea

Tuple: Immutable Ordered Collection

Locked-in list, safer data.

A tuple is an ordered, immutable sequence of items in Python. Once created, you cannot change, add, or remove elements. This makes tuples ideal for fixed data like coordinates or configuration constants.

↳ Tuples are immutable lists, perfect for data that should never change.

📖 Definition

Tuple Syntax

Parentheses, not brackets.

Create a tuple using parentheses `()` or just commas. A single-element tuple needs a trailing comma to avoid ambiguity with parentheses for grouping.

↳ Use parentheses and commas; remember the trailing comma for single-element tuples.

⚖️ Comparison

Tuple vs List

Mutable vs immutable choice.

↳ Choose tuples for safety and speed when data shouldn't change.

✏️ Example

Accessing Tuple Elements

Index and slice like lists.

↳ Use square-bracket indexing and slicing just like with lists.

💡 Key Idea

Tuple Unpacking

Assign multiple values at once.

Tuple unpacking lets you assign each element of a tuple to a separate variable in one line. This is a clean, Pythonic way to swap values or extract data.

↳ Unpack tuples for elegant, readable assignments.

⭐ Important Fact

Tuples as Dictionary Keys

Immutable = hashable = key.

Because tuples are immutable, they are hashable and can be used as dictionary keys. Lists, being mutable, cannot. This is perfect for mapping composite keys to values.

↳ Use tuples as dictionary keys when you need a compound identifier.

⚠️ Common Mistake

Forgetting Trailing Comma

Single-element tuple gotcha.

↳ Always include a trailing comma for single-element tuples.

🛠️ Application

Returning Multiple Values

Functions return tuples implicitly.

Python functions that return multiple values actually return a tuple. This is a common pattern for returning related data without creating a custom class.

↳ Use tuples to return multiple values from a function cleanly.

🧠 Memory Trick

Remember: Tuple = Two + People

Couple stays together forever.

Think of tuple like 'two people' (a couple) who are together permanently — you can't change who's in the couple. The word 'tuple' sounds like 'couple', and couples are (ideally) immutable!

↳ Tuple = couple = together forever = immutable.

✅ Best Practice

When to Use Tuples

Fixed data, safer code.

↳ Prefer tuples for constant collections; they make your intent clear.

💻 Code Example

Tuple Methods: count() and index()

Only two methods available.

Tuples have only two built-in methods: `count()` returns how many times a value appears, and `index()` returns the first index of a value.

↳ Use count() and index() for basic tuple queries.

🌍 Real World

GPS Coordinates as Tuples

Latitude and longitude locked.

GPS coordinates are a perfect real-world tuple: latitude and longitude are always paired and never change for a fixed location. Storing them as a tuple prevents accidental modification and allows use as dictionary keys.

↳ Tuples model fixed, paired data like coordinates naturally.

🎯 Exam Tip

Tuple vs List in Exams

Spot the immutable one.

Exam questions often test the difference: if you see `()` it's a tuple (immutable); if you see `[]` it's a list (mutable). Remember: tuples cannot be changed after creation — no append, remove, or item assignment.

↳ Parentheses = immutable; brackets = mutable.

🔗 Analogy

Tuple is Like a Sealed Envelope

Contents fixed once sealed.

Think of a tuple as a sealed envelope containing items. You can look inside (access elements), count how many items are there, or pass the envelope to someone else. But you cannot add, remove, or change anything without breaking the seal.

↳ Tuples are sealed containers — viewable but not modifiable.

❓ Did You Know

Tuple Performance Edge

Faster than lists for iteration.

Because tuples are immutable, Python can optimize them internally. Iterating over a tuple is slightly faster than iterating over a list. For large datasets that don't change, tuples can give a small performance boost.

↳ Tuples are faster than lists for read-only iteration.

⚙️ Process

Creating a Named Tuple

Tuple with field names.

For more readable code, use `namedtuple` from the `collections` module. It creates tuple-like objects with named fields, combining immutability with self-documenting code.

↳ Use namedtuple for immutable objects with named fields.

Smart notes

What you'll study, topic by topic

1

Tuples in Python

8 min

Tuples are immutable, ordered sequences in Python, created with parentheses and commas. They are ideal for fixed data, can be used as dictionary keys, and support indexing, slicing, and unpacking. Understanding when to u…

  • Tuples are immutable: once created, elements cannot be changed, added, or removed.
  • Use parentheses `()` and commas to create tuples; a trailing comma is required for single-element tuples.
  • Tuples support indexing, slicing, and all read-only operations like lists.

Full explanation, worked examples & memory tricks in the app

Leveled MCQ practice

Try the smart MCQs from this kit

All 19 questions, laddered from warm-up to topper-level, each with its answer and the reasoning behind it.

Warm-up · 10 questions

Q1. Which of the following is a correct way to create an empty tuple in Python?

Beginner
A empty = {}
B empty = []
C empty = ()
D empty = None

Answers and explanations are in the Veda app.

Q2. What is the output of `len((1, 2, 3))`?

Beginner
A 2
B 3
C 4
D 1

Answers and explanations are in the Veda app.

Q3. Which of the following correctly accesses the second element of tuple `t = (10, 20, 30)`?

Beginner
A t[1]
B t[0]
C t[-1]
D t[2]

Answers and explanations are in the Veda app.

Q4. What is the output of `(1, 2, 3) == (1, 2, 3)`?

Beginner
A Error
B False
C None
D True

Answers and explanations are in the Veda app.

Q5. What is the output of `t = (1, 2, 3); print(t[-1])`?

Beginner
A 1
B 2
C Error
D 3

Answers and explanations are in the Veda app.

Q6. Which built-in function converts a list to a tuple?

Beginner
A dict()
B list()
C set()
D tuple()

Answers and explanations are in the Veda app.

Q7. Tuples are mutable in Python.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Q8. A tuple can contain elements of different data types.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Q9. The `in` operator can be used to check if an element exists in a tuple.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Q10. Tuples support item assignment like lists.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Building up · 9 questions

Q11. Which of the following statements about tuples is TRUE?

Intermediate
A Tuples can be modified after creation.
B Tuples are immutable.
C Tuples are unordered collections.
D Tuples cannot contain duplicate elements.

Answers and explanations are in the Veda app.

Q12. What is the result of `(1, 2) + (3, 4)`?

Intermediate
A Error
B (1, 2, 3, 4)
C (1, 2, 3, 4, 5)
D (4, 6)

Answers and explanations are in the Veda app.

Q13. What does `(1, 2, 3) * 2` return?

Intermediate
A (1, 2, 3, 1, 2, 3)
B Error
C (2, 4, 6)
D (1, 2, 3, 2)

Answers and explanations are in the Veda app.

Q14. Which method can be used to find the index of a value in a tuple?

Intermediate
A locate()
B find()
C index()
D search()

Answers and explanations are in the Veda app.

Q15. Which of the following is NOT a valid tuple operation?

Intermediate
A t.count(2)
B t.append(4)
C t.index(2)
D len(t)

Answers and explanations are in the Veda app.

Q16. What is the type of `x` after `x = 1, 2, 3`?

Intermediate
A int
B tuple
C list
D set

Answers and explanations are in the Veda app.

Q17. What does `t = (1, 2, 3); a, b, c = t; print(a)` output?

Intermediate
A 2
B 3
C (1, 2, 3)
D 1

Answers and explanations are in the Veda app.

Q18. Which of the following creates a single-element tuple?

Intermediate
A t = (1,)
B t = (1)
C t = [1]
D t = 1

Answers and explanations are in the Veda app.

Q19. What is the result of `(1, 2, 3).count(2)`?

Intermediate
A 3
B 0
C 1
D 2

Answers and explanations are in the Veda app.

Flashcards

Tap a card to flip it

18 flashcards in this kit — the app reviews them with spaced repetition so the right card returns on the right day.

Study it properly — free, in the app

The full Veda Bites deck, complete notes, spaced-repetition flashcards, leveled MCQs, tests and games for this kit — plus Daily Facts and the Arena, every day.