Commerce

Tuples 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

  1. A. (4,6)
  2. B. (1,2,3,4)
  3. C. Error as tuples are immutable
  4. D. None
Report Error

What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:3]

  1. A. (1, 2)
  2. B. (1, 2, 4)
  3. C. (2, 4)
  4. D. (2, 4, 3)
Report Error

Is the following Python code valid? >>> a=(1,2,3) >>> b=a.update(4,)

  1. A. Yes, a=(1,2,3,4) and b=(1,2,3,4)
  2. B. Yes, a=(1,2,3) and b=(1,2,3,4)
  3. C. No because tuples are immutable
  4. D. No because wrong syntax for update() method
Report Error

What will be the output of the following Python code? >>> a=(1,2,(4,5)) >>> b=(1,2,(3,4)) >>> a<b

  1. A. False
  2. B. True
  3. C. Error, < operator is not valid for tuples
  4. D. Error, < operator is valid for tuples but not if there are sub-tuples
Report Error

Is the following Python code valid? >>> a=2,3,4,5 >>> a

  1. A. Yes, 2 is printed
  2. B. Yes, [2,3,4,5] is printed
  3. C. No, too many values to unpack
  4. D. Yes, (2,3,4,5) is printed
Report Error

Is the following Python code valid? >>> a,b=1,2,3

  1. A. Yes, this is an example of tuple unpacking. a=1 and b=2
  2. B. Yes, this is an example of tuple unpacking. a=(1,2) and b=3
  3. C. No, too many values to unpack
  4. D. Yes, this is an example of tuple unpacking. a=1 and b=(2,3)
Report Error

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)]

  1. A. [2, 3, 9]
  2. B. [1, 2, 4, 3, 8, 9]
  3. C. [1, 4, 8]
  4. D. (1, 4, 8)
Report Error

What will be the output of the following Python code? >>> a=(1,2,3,4) >>> del(a[2])

  1. A. Now, a=(1,2,4)
  2. B. Now, a=(1,3,4)
  3. C. Now a=(3,4)
  4. D. Error as tuple is immutable
Report Error

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)

  1. A. 1
  2. B. 2
  3. C. 5
  4. D. Error
Report Error

What will be the output of the following Python code? a = ('check',) n = 2 for i in range(int(n)): a = (a,) print(a)

  1. A. Error, tuples are immutable
  2. B. (('check',),) ((('check',),),)
  3. C. ((‘check’,)’check’,)
  4. D. (('check',)’check’,) ((('check',)’check’,)’check’,)
Report Error

What will be the output of the following Python code? >>> a=(2,3,1,5) >>> a.sort() >>> a

  1. A. (1,2,3,5)
  2. B. (2,3,1,5)
  3. C. None
  4. D. Error, tuple has no attribute sort
Report Error

What will be the output of the following Python code? >>> a=(2,3,4) >>> sum(a,3)

  1. A. Too many arguments for sum() method
  2. B. The method sum() doesn't exist for tuples
  3. C. 12
  4. D. 9
Report Error