Python Programming - Tuples

Exercise : Tuples - General Questions
  • Tuples - General Questions
16.
How can you find the index of the last occurrence of a specific element in a tuple?
tuple.last_index(element)
tuple.index_last(element)
tuple.index(element, -1)
tuple.find_last(element)
Answer: Option
Explanation:
The index() method can be used with a negative start parameter to find the last occurrence of an element.

17.
What is the result of the expression (1, 2, 3) * 2?
(1, 2, 3, 1, 2, 3)
((1, 2, 3), (1, 2, 3))
[1, 2, 3, 1, 2, 3]
(2, 4, 6)
Answer: Option
Explanation:
The '*' operator repeats the elements of the tuple.

18.
What is the primary difference between tuples and lists?
Tuples are mutable, while lists are immutable.
Tuples are ordered, while lists are unordered.
Tuples allow duplicate elements, while lists do not.
Tuples are immutable, while lists are mutable.
Answer: Option
Explanation:
Tuples cannot be modified once created, making them immutable.

19.
How do you create a tuple with the elements from 1 to 5?
new_tuple = (1, 2, 3, 4, 5)
new_tuple = tuple(range(1, 6))
new_tuple = (1 to 5)
new_tuple = [1, 2, 3, 4, 5]
Answer: Option
Explanation:
The range() function generates a sequence of numbers, and tuple() converts it to a tuple.

20.
Which method is used to remove the first occurrence of a specific element in a tuple?
tuple.delete(element)
tuple.remove(element)
tuple.discard(element)
tuple.pop(element)
Answer: Option
Explanation:
The remove() method is used to remove the first occurrence of a specific element in a tuple.