Dictionary???

Fredrik Lundh fredrik at pythonware.com
Wed Nov 17 14:11:04 CET 1999


Arinte <shouldbe at message.com> wrote:
> I looked in the tutorial and they gave a general overview.  It show how to
> view and delete items in a dictionary, but how do you add a pair to the
> dictionary?

http://www.python.org/doc/current/tut/node7.html

section 5.4:

    Here is a small example using a dictionary: 

    >>> tel = {'jack': 4098, 'sape': 4139}
    >>> tel['guido'] = 4127
    >>> tel
    {'sape': 4139, 'guido': 4127, 'jack': 4098}
    >>> tel['jack']
    4098
    >>> del tel['sape']
    >>> tel['irv'] = 4127
    >>> tel
    {'guido': 4127, 'irv': 4127, 'jack': 4098}
    >>> tel.keys()
    ['guido', 'irv', 'jack']
    >>> tel.has_key('guido')
    1

also see:
http://www.python.org/doc/current/lib/typesmapping.html

</F>





More information about the Python-list mailing list