🧩 Tuple Data Type

Last Updated: 17th August 2025


  • A tuple is an ordered, immutable collection in Python.
  • Once created, you cannot change its elements (no add/remove/modify).
  • Tuples use round brackets () and can store mixed types.
  • All the indexing and slicing operations work on tuples.
  • Store multiple data types items in a single variable.

Hinglish Tip 🗣: Tuple ko socho ek list jaisa jo lock ho gaya ho — values read kar sakte ho, par change nahi kar sakte.


✏ Syntax

# multiple items
t = (1, 2, 3)

# single item tuple (comma is required)
single = (10,)

# without parentheses (tuple packing)
packed = 1, 2, 3

# mixed types
mix = (1, "hello", 3.5)

Tuple Operations

t = (10, 20, 30, 40, 50)

print(t[0])      # Indexing → 10
print(t[-1])     # Negative Indexing → 50
print(t[1:4])    # Slicing → (20, 30, 40)

print(len(t))    # Length → 5
print(30 in t)   # Membership → True

print(t+(60, 70, 80)) # Concatenation → (10, 20, 30, 40, 50, 60, 70, 80)

print(t*3)       # Repetition → (10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50)

# Unpacking
a, b, c = t
print(a)  # 10
print(b)  # 20
print(c)  # 30

🔧 Tuple Methods

MethodUseExample
count()Count occurrences of a value(1,2,2,3).count(2) → 2
index()Return first index of value (10,20,30).index(20) → 1

💡 Quick Practice

  • Create a tuple of your favorite fruits.
  • Access the first and last fruits in the tuple.
  • Loop through the tuple and print each fruit.
  • Exercise