Python Tuples


A tuple is a collection which is ordered and unchangeable.
Tuples are written with round brackets ().


🔹 Create a Tuple

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

🔹 Tuple Items Are Ordered

Tuples keep the order in which items are added.

print(fruits[1])  # banana

🔹 Negative Indexing

print(fruits[-1])  # cherry

🔹 Tuple Length

print(len(fruits))  # 3

🔹 One-Item Tuple

Add a comma , to create a tuple with one item.

single = ("apple",)
print(type(single))  # <class 'tuple'>

🔹 Tuple with Different Data Types

mixed = ("apple", 5, True)

🔹 Tuple Constructor

t = tuple(("a", "b", "c"))

🔹 Loop Through Tuple

for item in fruits:
    print(item)

🔹 Check if Item Exists

if "banana" in fruits:
    print("Yes")

🔹 Change Tuple (via Conversion)

Tuples are unchangeable. Convert to list → change → convert back.

x = ("apple", "banana", "cherry")
temp = list(x)
temp[1] = "orange"
x = tuple(temp)
print(x)

🔹 Join Tuples

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

🧪 Try It Yourself

Create and access tuples, check membership, and combine tuples.


Practice Questions

Q1. Write a Python program to create a tuple of 5 programming languages and print it.

Q2. Write a Python program to print the second item of a tuple.

Q3. Write a Python program to print the last item of a tuple using negative indexing.

Q4. Write a Python program to check if "Java" exists in a tuple using the in keyword.

Q5. Write a Python program to convert a tuple to a list, change a value, and print the updated list.

Q6. Write a Python program to create a tuple with only one item and print its type.

Q7. Write a Python program to join two tuples together and print the result.

Q8. Write a Python program to loop through a tuple using a for loop and print each item.

Q9. Write a Python program to find the length of a tuple using the len() function.

Q10. Write a Python program to create a tuple with mixed data types (e.g., int, string, float) and print it.


Go Back Top