Page 108 - tp_Modula_v2.0
P. 108

Recap


                            Python dictionary is another data type, which contains a collection of values in the form of key
                           value pairs.
                           The data element of a dictionary can be retrieved or accessed by its key value.
                            Dictionary is a heterogeneous collection of data elements, where key must be unique and
                           immutable.
                           Elements of the dictionary can be access by using  the key defined in the key:value pairs.




                                                         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 these
                      3.   Python Dictionary are defined into …………………… element(s).

                           a.    Keys                                    b.    Values
                           c.    Both keys and values                    d.    None of these
                      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.



                  106     Touchpad MODULAR (Version 2.0)
   103   104   105   106   107   108   109   110   111   112   113