Python Programming - Tuples

Exercise : Tuples - General Questions
  • Tuples - General Questions
36.
How do you find the length of a tuple?
tuple.length()
tuple.size()
len(tuple)
length(tuple)
Answer: Option
Explanation:
The len() function is used to find the length of a tuple.

37.
What is the purpose of the tuple.count() method?
Counts the number of elements in the tuple.
Counts the occurrences of a specific element in the tuple.
Counts the number of unique elements in the tuple.
Counts the elements with even values in the tuple.
Answer: Option
Explanation:
The count() method is used to count the occurrences of a specific element in a tuple.

38.
What is the result of the expression tuple(('a', 'b', 'c'))[::-1]?
('a', 'b', 'c')
('c', 'b', 'a')
['c', 'b', 'a']
('c', 'b', 'a')
Answer: Option
Explanation:
The [::-1] slice reverses the order of elements in the tuple.

39.
Which of the following methods is used to find the index of the first occurrence of a specific element in a tuple?
tuple.find(element)
tuple.search(element)
tuple.index(element)
tuple.locate(element)
Answer: Option
Explanation:
The index() method is used to find the index of the first occurrence of a specific element in a tuple.

40.
What is the result of the expression tuple(('cat', 'dog', 'rabbit')) * 2?
('cat', 'dog', 'rabbit', 'cat', 'dog', 'rabbit')
['cat', 'dog', 'rabbit', 'cat', 'dog', 'rabbit']
(('cat', 'dog', 'rabbit'), ('cat', 'dog', 'rabbit'))
('catdograbbit', 'catdograbbit')
Answer: Option
Explanation:
The '*' operator is used to repeat the elements of the tuple.