Page 97 - Modular v1.1 Pyhton
P. 97
Exercise
A. Tick ( ) the correct option.
1. In Python, a Dictionary can be created by placing sequence of elements within ……………………
braces.
a. { } b. [ ]
c. ( ) d. \\
2. …………………… function(s) can also be used for deleting specific values from a Dictionary.
a. pop( ) b. popitem( )
c. Both a and b d. None of the above
3. Python Dictionary are defined into …………………… element(s).
a. Keys b. Values
c. Both keys and values d. None of the above
4. What will be the output of the following code:
x = {(1,2):2,(5,6):4}
print(x[1,2])
a. Index Error b. 1
c. 2 d. 0
B. Write ‘T’ for true and ‘F’ for false.
1. We cannot remove an element from a dictionary. ……………………
2. Dictionary key must be unique and immutable. ……………………
3. Element values of a dictionary can be access on the basis of the key values. ……………………
4. The get() method is used for fetching the value of a particular keys. ……………………
C. Fill in the blanks using the words given below.
pop( ), del, clear( ), popitem( )
1. …………………… method is used to remove the dictionary element with the specified key value.
2. …………………… method is used to remove all the elements of a dictionary.
3. …………………… method is used to remove arbitrary element from the Python dictionary.
4. …………………… method is used to delete a specific element or entire dictionary.
D. Short answer type questions.
1. What is dictionary?
2. What do you mean by accessing a dictionary?
3. How will you update an element in a dictionary?
E. Long answer type questions.
1. How will you create a dictionary? Explain with an example.
Dictionary in Python 95

