Home > Python > Quizzes > Python Programming Basics Practice Test: Python Dictionary
Python Programming Basics Practice Test: Python Dictionary
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 18% Most missed: “What will be the output of the following Python code snippet?”
A Python dictionary is a collection of data that is stored in key-value pairs. Keys are unique identifiers, and values can be any type of data, such as numbers, strings, lists, or even other dictionaries. Dictionaries are created using curly braces ({}), and each key-value pair is separated by a comma.  You can also use the get() method to access the value of a key. The get() method takes the key as an argument and returns the value associated with the key, or None if the key does not exist. Dictionaries are a powerful data structure that can be used to store and organize data in a variety... Show more
Python Programming Basics Practice Test: Python Dictionary
Time left 00:00
25 Questions

1. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
2. Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?
3. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?
4. What will be the output of the following Python code snippet?
>>>import collections
>>> a=collections.Counter([1,1,2,3,3,4,4,4])
>>> a
5. What will be the output of the following Python code snippet?
total={}
def insert(items):
if items in total:
total[items] += 1
else:
total[items] = 1
insert('Apple')
insert('Ball')
insert('Apple')
print (len(total))
6. If a is a dictionary with some key-value pairs, what does a.popitem() do?
7. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 == d2
8. What will be the output of the following Python code snippet?
test = {1:'A', 2:'B', 3:'C'}
test = {}
print(len(test))
9. Which of the following is not a declaration of the dictionary?
10. What will be the output of the following Python code?
>>> a={1:"A",2:"B",3:"C"}
>>> a.items()
11. If b is a dictionary, what does any(b) do?
12. What will be the output of the following Python code snippet?
a={}
a['a']=1
a['b']=[2,3,4]
print(a)
13. What will be the output of the following Python code snippet?
test = {1:'A', 2:'B', 3:'C'}
del test[1]
test[1] = 'D'
del test[2]
print(len(test))
14. What will be the output of the following Python code snippet?
>>> import collections
>>> a=collections.Counter([2,2,3,3,3,4])
>>> b=collections.Counter([2,2,3,4,4])
>>> a|b
15. What will be the output of the following Python code?
a={1:5,2:3,3:4}
print(a.pop(4,9))
16. What will be the output of the following Python code?
>>> a={i: 'A' + str(i) for i in range(5)}
>>> a
17. What will be the output of the following Python code snippet?
a = {}
a[1] = 1
a['1'] = 2
a[1]=a[1]+1
count = 0
for i in a:
count += a[i]
print(count)
18. What will be the output of the following Python code snippet?
>>>import collections
>>> b=collections.Counter([2,2,3,4,4,4])
>>> b.most_common(1)
19. What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
for i in a:
print(i,end=" ")
20. What will be the output of the following Python code snippet?
a = {}
a[1] = 1
a['1'] = 2
a[1.0]=4
count = 0
for i in a:
count += a[i]
print(count)
21. What will be the output of the following Python code?
>>> import collections
>>> a=dict()
>>> a=collections.defaultdict(int)
>>> a[1]
22. What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
d["john"]
23. What will be the output of the following Python code snippet?
>>> import collections
>>> a=collections.Counter([3,3,4,5])
>>> b=collections.Counter([3,4,4,5,5,5])
>>> a&b
24. What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
25. What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
for i,j in a.items():
print(i,j,end=" ")