Python Programming - Tuples

Exercise : Tuples - General Questions
  • Tuples - General Questions
21.
What is the correct way to access the second element of a tuple?
tuple[2]
tuple.get(1)
tuple[1]
tuple.element(2)
Answer: Option
Explanation:
In Python, indexing starts from 0, so the second element can be accessed using index 1.

22.
What does the sorted() function return when applied to a tuple?
A sorted list
A sorted tuple
Raises a TypeError
An error, as tuples cannot be sorted
Answer: Option
Explanation:
The sorted() function returns a sorted list, even when applied to a tuple.

23.
How do you create a tuple with repeated elements?
new_tuple = (1, 2, 1, 2, 1, 2)
new_tuple = tuple(1, 2, 1, 2, 1, 2)
new_tuple = (1, 2) * 3
new_tuple = tuple.repeat(1, 2)
Answer: Option
Explanation:
Repeating elements can be done directly within the tuple.

24.
Which of the following methods is used to find the total number of occurrences of a specific element in a tuple?
tuple.total(element)
tuple.count(element)
tuple.find(element)
tuple.occurrences(element)
Answer: Option
Explanation:
The count() method is used to find the total number of occurrences of a specific element in a tuple.

25.
What is the result of the expression len(('apple', 'orange', 'banana'))?
3
6
16
1
Answer: Option
Explanation:
The len() function returns the number of elements in the tuple, and in this case, there are three elements.