Creating an array and a dictionary and printing values

  1. Define a small array:

    >>> phonelist = [938477566, 938377264,947662781]

  2. Print out the contents of the array:

    >>> print phonelist

    [938477566, 938377264, 947662781]

  3. Print out the value of one of the records in the array:

    >>> print phonelist[0]

    938477566

  4. Define a small dictionary:

    >>> phonebook = {"John" : 938477566, "Jack" : 938377264, "Jill" : 947662781}

  5. Print out the contents of the dictionary:

    >>> print phonebook

    {'Jill': 947662781, 'John': 938477566, 'Jack': 938377264}

  6. Print out the value of one of the records in the dictionary:

    >>> print phonebook["John"]

    938477566

See also

Starting the Python shell

Printing hello world

Using basic variables

Looping through a predefined list

Looping using the xrange function