Python Programming - Tuples

Exercise : Tuples - General Questions
  • Tuples - General Questions
31.
What is the purpose of the tuple() constructor?
Creates an empty tuple.
Converts a list to a tuple.
Converts a string to a tuple.
All of the above.
Answer: Option
Explanation:
The tuple() constructor can be used for various purposes, including creating an empty tuple and converting other data types to tuples.

32.
What is the result of the expression (1, 2, 3) + (4,)?
(1, 2, 3, 4)
((1, 2, 3), (4,))
[1, 2, 3, 4]
(1, 2, 3, (4,))
Answer: Option
Explanation:
The '+' operator concatenates the two tuples.

33.
Which of the following methods is used to 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 with a negative start parameter can be used to find the last occurrence of an element.

34.
What is the output of the expression max(('apple', 'orange', 'banana'))?
'apple'
'banana'
'orange'
Raises a TypeError
Answer: Option
Explanation:
The max() function returns the largest element in the tuple based on lexicographic order.

35.
What is the result of the expression tuple('hello')?
('h', 'e', 'l', 'l', 'o')
(104, 101, 108, 108, 111)
('hello')
['h', 'e', 'l', 'l', 'o']
Answer: Option
Explanation:
The tuple() constructor can convert a string to a tuple of its characters.