Python Programming - Tuples

Exercise : Tuples - General Questions
  • Tuples - General Questions
6.
Which of the following statements about tuples in Python is correct?
Tuples allow in-place modification of elements.
Tuples can be nested to any level.
Tuples can only contain elements of the same data type.
Tuples support random access of elements by index.
Answer: Option
Explanation:
Tuples in Python can contain other tuples, allowing nesting to any level.

7.
How do you convert a list to a tuple?
tuple(list)
list.to_tuple()
(tuple)list
list.as_tuple()
Answer: Option
Explanation:
The tuple() constructor can be used to convert a list to a tuple.

8.
What is the result of the expression (1, 2, 3) + (4, 5, 6)?
(1, 2, 3, 4, 5, 6)
((1, 2, 3), (4, 5, 6))
[1, 2, 3, 4, 5, 6]
(5, 7, 9)
Answer: Option
Explanation:
The '+' operator concatenates tuples in Python.

9.
Which method is used to find the index of a specific element in a tuple?
index()
find()
get_index()
search()
Answer: Option
Explanation:
The index() method is used to find the index of a specific element in a tuple.

10.
What is the output of len((1, [2, 3], 'hello'))?
3
4
5
6
Answer: Option
Explanation:
The len() function returns the number of elements in the tuple, and in this case, there are three elements.