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? d = {"john":40, "peter":45} d["john"]
- A. 40
- B. 45
- C. "john"
- D. "peter"
Correct Answer: A
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)
- A. 30
- B. 24
- C. 33
- D. 12
Correct Answer: C
If a=(1,2,3,4), a[1:-1] is . . . . . . . .
- A. Error, tuple slicing doesn't exist
- B. [2,3]
- C. (2,3,4)
- D. (2,3)
Correct Answer: D
What will be the output of the following Python code? >>> a,b=6,7 >>> a,b=b,a >>> a,b
- A. (6,7)
- B. Invalid syntax
- C. (7,6)
- D. Nothing is printed
Correct Answer: C
What will be the output of the following Python code? >>>t = (1, 2) >>>2 * t
- A. (1, 2, 1, 2)
- B. [1, 2, 1, 2]
- C. (1, 1, 2, 2)
- D. [1, 1, 2, 2]
Correct Answer: A
Is the following Python code valid? >>> a,b,c=1,2,3 >>> a,b,c
- A. Yes, [1,2,3] is printed
- B. No, invalid syntax
- C. Yes, (1,2,3) is printed
- D. 1 is printed
Correct Answer: C
What will be the output of the following Python code? >>> a=(0,1,2,3,4) >>> b=slice(0,2) >>> a[b]
- A. Invalid syntax for slicing
- B. [0,2]
- C. (0,1)
- D. (0,2)
Correct Answer: C
Tuples can't be made keys of a dictionary.
- A. True
- B. False
Correct Answer: B
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
- A. a(i=4, j=7)
- B. obj(i=4, j=7)
- C. (4,7)
- D. An exception is thrown
Correct Answer: A
What type of data is: a=[(1,1),(2,4),(3,9)]?
- A. Array of tuples
- B. List of tuples
- C. Tuples of lists
- D. Invalid type
Correct Answer: B
What will be the output of the following Python code? >>> a=[(2,4),(1,2),(3,9)] >>> a.sort() >>> a
- A. [(1, 2), (2, 4), (3, 9)]
- B. [(2,4),(1,2),(3,9)]
- C. Error because tuples are immutable
- D. Error, tuple has no sort attribute
Correct Answer: A
Suppose t = (1, 2, 4, 3), which of the following is incorrect?
- A. print(t[3])
- B. t[3] = 45
- C. print(max(t))
- D. print(len(t))
Correct Answer: B