CommerceTuples In Python MCQs
Practice Tuples In Python MCQs for competitive exams.
Tuples In Python MCQs
Practice questions from this topic.
Is the following Python code valid? >>> a=(1,2,3,4) >>> del a
- A. No because tuple is immutable
- B. Yes, first element in the tuple is deleted
- C. Yes, the entire tuple is deleted
- D. No, invalid syntax for del method
Correct Answer: C
What will be the output of the following Python code? >>> a=("Check")*3 >>> a
- A. ('Check','Check','Check')
- B. * Operator not valid for tuples
- C. ('CheckCheckCheck')
- D. Syntax error
Correct Answer: C
Is the following Python code valid? >>> a=(1,2,3) >>> b=('A','B','C') >>> c=tuple(zip(a,b))
- A. Yes, c will be ((1, 'A'), (2, 'B'), (3, 'C'))
- B. Yes, c will be ((1,2,3),('A','B','C'))
- C. No because tuples are immutable
- D. No because the syntax for zip function isn't valid
Correct Answer: A
What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:-1]
- A. (1, 2)
- B. (1, 2, 4)
- C. (2, 4)
- D. (2, 4, 3)
Correct Answer: C
What is the data type of (1)?
- A. Tuple
- B. Integer
- C. List
- D. Both tuple and integer
Correct Answer: B
What will be the output of the following Python code? >>>t1 = (1, 2, 4, 3) >>>t2 = (1, 2, 3, 4) >>>t1 < t2
- A. True
- B. False
- C. Error
- D. None
Correct Answer: B
What will the following code output: my_tuple = (1, 2, 3) new_tuple = my_tuple.copy() print(new_tuple)
- A. (1, 2, 3)
- B. (1, 2, 3, 1, 2, 3)
- C. (1, 1, 2, 2, 3, 3)
- D. (2, 1, 3)
Correct Answer: A
What is the output of the following code: my_tuple = (1, 2, 3) print(my_tuple[1])
- A. 1
- B. 2
- C. 3
- D. Error
Correct Answer: B
What is the purpose of the count() method for lists and tuples?
- A. Counts the occurrences of a specific element
- B. Adds the elements of one list or tuple to another
- C. Finds the index of a specific element
- D. Reverses the list or tuple
Correct Answer: A
What will be the output of the following code: my_tuple = (1, 2, 3) my_tuple[1] = 4 print(my_tuple)
- A. (1, 2, 3)
- B. (4, 2, 3)
- C. (1, 4, 3)
- D. None of these
Correct Answer: D
What is the purpose of the reverse() method for lists and tuples?
- A. Reverses the order of elements in the list or tuple
- B. Removes the last element
- C. Deletes the list or tuple
- D. Adds an element to the list or tuple
Correct Answer: A
In Python, how can you remove all occurrences of a specific element from a list or tuple?
- A. Use a loop and remove() method
- B. delete_all()
- C. clear()
- D. discard_all()
Correct Answer: A