Day 23 Python Answers - 60062370 - 2025 - 05 - 17 - 21 - 28
Day 23 Python Answers - 60062370 - 2025 - 05 - 17 - 21 - 28
Day 23
Syllabus Coverage
- Tuples in Python
- Built-in functions: `len()`, `tuple()`, `count()`, `index()`, `sorted()`, `min()`, `max()`, `sum()`.
- Suggested programs: finding minimum, maximum, mean; linear search; counting frequency
of elements.
Answer:
Tuple Assignment:
Example:
# Tuple assignment
a, b = 10, 20
# Swapping values
a, b = b, a
Nested Tuples:
Example:
2. Why are tuples considered immutable? How does this affect operations like insertion and
deletion? (5 Marks)
Answer:
Immutability of Tuples:
• Makes them faster than lists and suitable for fixed data (e.g., dictionary keys).
Impact on Operations:
• Insertion: Not allowed. Use + to concatenate new elements into a new tuple.
tuple1 = (1, 2)
tuple3 = (1, 2, 3, 4)
Programming Solutions
1. Find the index of a specified element in a tuple using the index() method. (3 Marks)
element = 20
index = my_tuple.index(element)
Output:
Index of 20 is: 1
minimum = min(numbers)
maximum = max(numbers)
print("Minimum:", minimum)
print("Maximum:", maximum)
print("Mean:", mean)
Output:
Minimum: 5
Maximum: 25
Mean: 15.0
3. Convert a list into a tuple and vice versa. (4 Marks)
# List to Tuple
my_list = [1, 2, 3]
list_to_tuple = tuple(my_list)
# Tuple to List
my_tuple = (4, 5, 6)
tuple_to_list = list(my_tuple)
Output: