CommerceTuples In Python MCQs
Practice Tuples In Python MCQs for competitive exams.
Tuples In Python MCQs
Practice questions from this topic.
What will be the output of the following Python code? >>> a=(1,2) >>> b=(3,4) >>> c=a+b >>> c
- A. (4,6)
- B. (1,2,3,4)
- C. Error as tuples are immutable
- D. None
Correct Answer: B
What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:3]
- A. (1, 2)
- B. (1, 2, 4)
- C. (2, 4)
- D. (2, 4, 3)
Correct Answer: C
Is the following Python code valid? >>> a=(1,2,3) >>> b=a.update(4,)
- A. Yes, a=(1,2,3,4) and b=(1,2,3,4)
- B. Yes, a=(1,2,3) and b=(1,2,3,4)
- C. No because tuples are immutable
- D. No because wrong syntax for update() method
Correct Answer: C
What will be the output of the following Python code? >>> a=(1,2,(4,5)) >>> b=(1,2,(3,4)) >>> a<b
- A. False
- B. True
- C. Error, < operator is not valid for tuples
- D. Error, < operator is valid for tuples but not if there are sub-tuples
Correct Answer: A
Is the following Python code valid? >>> a=2,3,4,5 >>> a
- A. Yes, 2 is printed
- B. Yes, [2,3,4,5] is printed
- C. No, too many values to unpack
- D. Yes, (2,3,4,5) is printed
Correct Answer: D
Is the following Python code valid? >>> a,b=1,2,3
- A. Yes, this is an example of tuple unpacking. a=1 and b=2
- B. Yes, this is an example of tuple unpacking. a=(1,2) and b=3
- C. No, too many values to unpack
- D. Yes, this is an example of tuple unpacking. a=1 and b=(2,3)
Correct Answer: C
What will be the output of the following Python code? >>>t = (1, 2, 4, 3, 8, 9) >>>[t[i] for i in range(0, len(t), 2)]
- A. [2, 3, 9]
- B. [1, 2, 4, 3, 8, 9]
- C. [1, 4, 8]
- D. (1, 4, 8)
Correct Answer: C
What will be the output of the following Python code? >>> a=(1,2,3,4) >>> del(a[2])
- A. Now, a=(1,2,4)
- B. Now, a=(1,3,4)
- C. Now a=(3,4)
- D. Error as tuple is immutable
Correct Answer: D
What will be the output of the following Python code? >>>my_tuple = (1, 2, 3, 4) >>>my_tuple.append( (5, 6, 7) ) >>>print len(my_tuple)
- A. 1
- B. 2
- C. 5
- D. Error
Correct Answer: D
What will be the output of the following Python code? a = ('check',) n = 2 for i in range(int(n)): a = (a,) print(a)
- A. Error, tuples are immutable
- B. (('check',),) ((('check',),),)
- C. ((‘check’,)’check’,)
- D. (('check',)’check’,) ((('check',)’check’,)’check’,)
Correct Answer: B
What will be the output of the following Python code? >>> a=(2,3,1,5) >>> a.sort() >>> a
- A. (1,2,3,5)
- B. (2,3,1,5)
- C. None
- D. Error, tuple has no attribute sort
Correct Answer: D
What will be the output of the following Python code? >>> a=(2,3,4) >>> sum(a,3)
- A. Too many arguments for sum() method
- B. The method sum() doesn't exist for tuples
- C. 12
- D. 9
Correct Answer: C