Page 428 - Computer Science V2.0 Class 11
P. 428

dictionary.keys()  Returns a dict_keys object comprising all  >>>dictionary =
                                         the keys included in the dictionary.  {1:'A',2:'B',3:'C'}

                                                                               >>>dictionary.keys()
                                                                               dict_keys([1, 2, 3])
               dictionary.               Returns a dict_values object comprising  >>>dictionary =
               values()                  all the values included in the dictionary.  {1:'A',2:'B',3:'C'}
                                                                               >>>dictionary.values()
                                                                               dict_values(['A', 'B', 'C'])
               dictionary.items() Returns a dict_items  object comprising  >>>dictionary =
                                         the set of items included in the dictionary. {1:'A',2:'B',3:'C'}
                                                                               >>>dictionary.items()
                                                                               dict_items([(1, 'A'), (2,
                                                                               'B'), (3, 'C')])
               dictionary.               Adds  all  key-value  pairs  of  another  >>>dictionary_d1=
               update()                  dictionary  to  an  existing  dictionary  {1:'A',2:'B',3:'C'}
                                         dictionary.                           >>>dictionary_d2=
                                                                               {4:'D',5:'E'}
                                                                               >>>dictionary_
                                                                               d1.update(dictionary_d2)

                                                                               >>>dictionary_d1
                                                                               {1: 'A', 2: 'B', 3: 'C', 4:
                                                                               'D', 5: 'E'}
               dictionary.               returns  a  value  for  the  key  (myKey)  >>>dictionary_d1=
               pop(myKey)                passed as an argument, and removes the  {1:'A',2:'B',3:'C'}

                                         item (myKey:myValue) with the specified  >>>dictionary_d1.pop(2)
                                         key from the dictionary.
                                                                               ‘B’
               dictionary.               Removes  the  last  inserted  item  (key- >>>dictionary_d1=
               popitem()                 value pair) from the dictionary.      {1:'A',2:'B',3:'C'}
                                                                               >>>dictionary_d1.popitem()
                                                                               (3, 'C')
               dictionary.clear() Removes  all  key-value  pairs  from  the  >>>dictionary_d1=
                                         dictionary.                           {1:'A',2:'B',3:'C'}

                                                                               >>>dictionary_d1.clear()
                                                                               >>>dictionary_d1
                                                                               {}
               dictionary.               Returns  the  value  of  the  item  with  the  >>>dictionary_d1=
               get(myKey, val)           specified key (myKey).                {1:'A',2:'B',3:'C'}
                                                                               >>>dictionary_d1.get(1)
                                                                               ‘A’
               dictionary.copy()  Returns a copy of the dictionary.            >>>dictionary_d1=
                                                                               {1:'A',2:'B',3:'C'}
                                                                               >>>dictionary_d1.copy()

                                                                               {1: 'A', 2: 'B', 3: 'C'}

               414   Touchpad Computer Science (Ver. 2.0)-XI
   423   424   425   426   427   428   429   430   431   432   433