Arrays

John Machin sjmachin at lexicon.net
Tue Nov 13 01:58:20 EST 2007


Bernard wrote:
> On 12 nov, 20:19, "Gordon C" <gc... at vif.com> wrote:
> > Absolute newbie here. In spite of the Python Software Foundation tutorial's
> > (http://www.python.org/doc/current/tut/tut.html) use of the array
> > declaration
> >   array(type[,initializer]), the Python interpreter does NOT accept the word
> > array! It , presumably, needs to have an import <something> included. Could
> > some show me how to declare arrays with some basic examples?
> > Gord.
>
> hey Gordon,
>
> here's a good reading for you: http://effbot.org/zone/python-list.htm

Hey Bernard, read Gordon's message carefully; he's asking about
arrays, not lists.

Hey Gordon, You seem a little lost; here's the tutorial reference:
http://docs.python.org/tut/node13.html#SECTION0013700000000000000000
which produces:
"""
The array module provides an array() object that is like a list that
stores only homogenous data and stores it more compactly. The
following example shows an array of numbers stored as two byte
unsigned binary numbers (typecode "H") rather than the usual 16 bytes
per entry for regular lists of python int objects:


    >>> from array import array
    >>> a = array('H', [4000, 10, 700, 22222])
    >>> sum(a)
    26932
    >>> a[1:3]
    array('H', [10, 700])
"""

The 2nd word (array) is a link (http://docs.python.org/lib/module-
array.html) to the docs for the array module.

Cheers,
John




More information about the Python-list mailing list