Python Programming - Tuples

Exercise : Tuples - General Questions
  • Tuples - General Questions
41.
How can you delete an entire tuple?
delete(tuple)
del tuple
tuple.delete()
tuple.clear()
Answer: Option
Explanation:
The del keyword is used to delete a tuple.

42.
What is the purpose of the tuple.extend() method?
Extends the size of the tuple.
Adds elements to the end of the tuple.
Merges two tuples into a new one.
Raises a TypeError
Answer: Option
Explanation:
The tuple type in Python does not have an extend() method.

43.
Which of the following statements about tuples in Python is correct?
Tuples allow duplicate elements.
Tuples can be directly modified using indexing.
Tuples support dynamic resizing.
Tuples must contain elements of same data types.
Answer: Option
Explanation:
Tuples can contain duplicate elements as they are ordered and allow repetition.

44.
What is the output of the expression tuple('python')[::-1]?
('n', 'o', 'h', 't', 'y', 'p')
('p', 'y', 't', 'h', 'o', 'n')
['n', 'o', 'h', 't', 'y', 'p']
('n', 'o', 'h', 't', 'y', 'p')
Answer: Option
Explanation:
The [::-1] slice reverses the order of elements in the tuple.

45.
What is the purpose of the tuple.__contains__(element) method?
Checks if the tuple contains the specified element.
Adds the specified element to the tuple.
Removes the specified element from the tuple.
Returns the count of occurrences of the specified element.
Answer: Option
Explanation:
The __contains__ method is used to check if the tuple contains a specified element.