Python Programming - Tuples

Exercise : Tuples - General Questions
  • Tuples - General Questions
11.
How can you check if a specific element exists in a tuple?
element in tuple
tuple.exists(element)
tuple.contains(element)
element.exist_in(tuple)
Answer: Option
Explanation:
Using the in keyword, you can check if an element exists in a tuple.

12.
What is the purpose of the tuple.index() method?
Returns the total number of elements in the tuple.
Finds the index of the last occurrence of a specific element.
Finds the index of the first occurrence of a specific element.
Adds a new element to the end of the tuple.
Answer: Option
Explanation:
The index() method is used to find the index of the first occurrence of a specific element in a tuple.

13.
Which of the following statements about tuples is true?
Tuples are mutable.
Tuples support item assignment.
Tuples can store heterogeneous data types,.
Tuples can be resized dynamically.
Answer: Option
Explanation:
Tuples in Python can store elements of different data types.

14.
How can you create a tuple with a single element?
single_tuple = (1)
single_tuple = (1,)
single_tuple = 1
single_tuple = tuple(1)
Answer: Option
Explanation:
Using a comma after the single element ensures it is treated as a tuple.

15.
What happens if you try to concatenate two tuples using the '+' operator?
Raises a TypeError
Merges the tuples into a single tuple.
Creates a list containing both tuples.
Concatenates the tuples into a new tuple.
Answer: Option
Explanation:
The '+' operator concatenates tuples, creating a new tuple with elements from both tuples.