Python Tutorial in Hindi #8 - Tuples

Python Tuples Explained | Immutable Data Structure Tutorial for Beginners | Mohit Decodes


Python Tuples Full Tutorial – Learn Immutable Data Structures

In this beginner-friendly Python video by Mohit Decodes, you’ll explore tuples — a core immutable data structure in Python.


✅ Topics Covered:

What are Tuples and Why Use Them?

Creating Tuples in Python

Accessing Tuple Items via Index

Slicing Tuples

Useful Tuple Methods (count(), index())

Real-world use cases and best practices



# 1️⃣ Creating a Tuple
fruits = ("apple", "banana", "mango", "orange")
print("Tuple:", fruits)
print("Type:", type(fruits))

# 2️⃣ Accessing Tuple Elements
print("First Element:", fruits[0])
print("Last Element:", fruits[-1])

# 3️⃣ Slicing Tuples
print("First 2 Fruits:", fruits[0:2])
print("From index 1 till end:", fruits[1:])
print("All Fruits:", fruits[:])

# 4️⃣ Tuple is Immutable
# fruits[0] = "grapes" ❌ This will throw an error
print("Tuples are immutable, so you cannot change their elements!")

# 5️⃣ Tuple with Different Data Types
mixed = ("Mohit", 25, True, 4.5)
print("Mixed Tuple:", mixed)

# 6️⃣ Length of Tuple
print("Length:", len(fruits))

# 7️⃣ Tuple Methods
numbers = (1, 2, 3, 2, 4, 2, 5)
print("Numbers Tuple:", numbers)
print("Count of 2:", numbers.count(2))
print("Index of 4:", numbers.index(4))

# 8️⃣ Nested Tuple
nested = ((1, 2, 3), ("A", "B", "C"))
print("Nested Tuple:", nested)
print("Access Nested Value:", nested[1][2]) # Output: C

# 9️⃣ Tuple without Parentheses
colors = "red", "green", "blue"
print("Tuple without brackets:", colors)
print("Type:", type(colors))

# 🔟 Converting List to Tuple and Tuple to List
list_data = [10, 20, 30]
tuple_data = tuple(list_data)
print("List to Tuple:", tuple_data)

new_list = list(tuple_data)
print("Tuple to List:", new_list)

# ✅ Mini Challenge
# Write a program to store 5 city names in a tuple and print them in reverse order
cities = ("Delhi", "Mumbai", "Kolkata", "Chennai", "Pune")
print("Cities Tuple:", cities)
print("Cities in Reverse:", cities[::-1])