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.


Python Tuples Quiz

Q1: What symbol is used to define a tuple?

A. []
B. {}
C. ()
D. <>

Q2: What is the key difference between a list and a tuple?

A. Tuples are mutable
B. Tuples are faster
C. Tuples are unchangeable
D. Lists are unchangeable

Q3: How do you create a single-item tuple?

A. ("apple")
B. ("apple",)
C. tuple("apple")
D. ["apple"]

Q4: What will len(("a", "b", "c")) return?

A. 2
B. 3
C. 1
D. Error

Q5: Can tuples have duplicate items?

A. No
B. Yes
C. Only integers
D. Only strings

Q6: Which function is used to create a tuple?

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

Q7: What will ("a", "b") + ("c",) return?

A. ["a", "b", "c"]
B. Error
C. ('a', 'b', 'c')
D. None

Q8: Can tuples contain different data types?

A. No
B. Only strings
C. Yes
D. Only integers

Q9: How do you loop through a tuple?

A. if
B. while
C. for
D. switch

Q10: What method converts a tuple to a list?

A. list()
B. str()
C. tuple()
D. change()

Go Back Top