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? d = {"john":40, "peter":45} d["john"]

  1. A. 40
  2. B. 45
  3. C. "john"
  4. D. "peter"
Report Error

What will be the output of the following Python code? numberGames = {} numberGames[(1,2,4)] = 8 numberGames[(4,2,1)] = 10 numberGames[(1,2)] = 12 sum = 0 for k in numberGames: sum += numberGames[k] print(len(numberGames) + sum)

  1. A. 30
  2. B. 24
  3. C. 33
  4. D. 12
Report Error

If a=(1,2,3,4), a[1:-1] is . . . . . . . .

  1. A. Error, tuple slicing doesn't exist
  2. B. [2,3]
  3. C. (2,3,4)
  4. D. (2,3)
Report Error

What will be the output of the following Python code? >>> a,b=6,7 >>> a,b=b,a >>> a,b

  1. A. (6,7)
  2. B. Invalid syntax
  3. C. (7,6)
  4. D. Nothing is printed
Report Error

What will be the output of the following Python code? >>>t = (1, 2) >>>2 * t

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

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

  1. A. Yes, [1,2,3] is printed
  2. B. No, invalid syntax
  3. C. Yes, (1,2,3) is printed
  4. D. 1 is printed
Report Error

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

  1. A. Invalid syntax for slicing
  2. B. [0,2]
  3. C. (0,1)
  4. D. (0,2)
Report Error

Tuples can't be made keys of a dictionary.

  1. A. True
  2. B. False
Report Error

What will be the output of the following Python code? >>> import collections >>> a=collections.namedtuple('a',['i','j']) >>> obj=a(i=4,j=7) >>> obj

  1. A. a(i=4, j=7)
  2. B. obj(i=4, j=7)
  3. C. (4,7)
  4. D. An exception is thrown
Report Error

What type of data is: a=[(1,1),(2,4),(3,9)]?

  1. A. Array of tuples
  2. B. List of tuples
  3. C. Tuples of lists
  4. D. Invalid type
Report Error

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

  1. A. [(1, 2), (2, 4), (3, 9)]
  2. B. [(2,4),(1,2),(3,9)]
  3. C. Error because tuples are immutable
  4. D. Error, tuple has no sort attribute
Report Error

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

  1. A. print(t[3])
  2. B. t[3] = 45
  3. C. print(max(t))
  4. D. print(len(t))
Report Error