• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech

Python Dictionary Quiz

Question 1

Question 1:Find the output of the following program: Python3
D = dict() 
for x in enumerate(range(2)): 
	D[x[0]] = x[1] 
	D[x[1]+7] = x[0] 
print(D) 
  • {0: 1, 7: 0, 1: 1, 8: 0}
  • {1: 1, 7: 2, 0: 1, 8: 1}
  • {0: 0, 7: 0, 1: 1, 8: 1}
  • KeyError

Question 2

Question 2:Find the output of the following program: Python3
D = {1 : 1, 2 : '2', '1' : 1, '2' : 3} 
D['1'] = 2
print(D[D[D[str(D[1])]]]) 
  • 2
  • 3
  • \'2\'
  • KeyError

Question 3

Question 3:Find the output of the following program: Python3
D = {1 : {'A' : {1 : "A"}, 2 : "B"}, 3 :"C", 'B' : "D", "D": 'E'} 
print(D[D[D[1][2]]], end = " ") 
print(D[D[1]["A"][2]]) 
  • C B
  • E Key Error
  • B D
  • D B

Question 4

Question 4:Find the output of the following program: Python3
D = dict() 
for i in range (3): 
	for j in range(2): 
		D[i] = j 
print(D) 
  • {0: 0, 1: 0, 2: 0}
  • {0: 1, 1: 1, 2: 1}
  • {0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1}
  • TypeError: Immutable object

Question 5

Question 5:Find the output of the following program: Python3
D = {1 : [1, 2, 3], 2: (4, 6, 8)} 
D[1].append(4) 
print(D[1], end = " ") 
L = [D[2]]
L.append(10) 
D[2] = tuple(L) 
print(D[2]) 
  • [1, 2, 3, 4] ((4, 6, 8), 10)
  • [1, 2, 3, 4] (4, 6, 8, 10)
  • [1, 2, 3, 4] TypeError: tuples are immutable
  • [1, 2, 3, 4] [4, 6, 8, 10]

Question 6

Question 6:Find the output of the following program: Python3
a = {i: i * i for i in range(6)} 
print (a) 
  • Dictionary comprehension doesn’t exist
  • {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}
  • {0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}
  • {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

Question 7

Question 7:Find the output of the following program: Python3
a ={} 
a.fromkeys(['a', 'b', 'c', 'd'], 98) 
print (a) 
  • Syntax error
  • {‘a’:98, ‘b’:98, ‘c’:98, ‘d’:98}
  • {‘a’:None, ‘b’:None, ‘c’:None.’d’:None}
  • { }

Question 8

Question 8:Find the output of the following program: Python3
dict ={} 
print (all(dict)) 
  • { }
  • False
  • True
  • An exception is thrown

Question 9

Question 9:Find the output of the following program: Python3
a = {'geeks' : 1, 'gfg' : 2} 
b = {'geeks' : 2, 'gfg' : 1} 
print (a == b) 
  • True
  • False
  • Error
  • None

Question 10

Question 10:Find the output of the following program: Which of these about a dictionary is false?
  • The values of a dictionary can be accessed using keys
  • The keys of a dictionary can be accessed using values
  • Dictionaries may or may not be ordered
  • None of the above

There are 25 questions to complete.

Last Updated :
Take a part in the ongoing discussion