Silly Question

Gerhard Häring gerhard.haering at opus-gmbh.net
Tue Mar 11 08:38:16 EST 2003


Clint Bailey <Photoman6x6 at hotmail.com> wrote:
> I've been studying Magnus Lie Hetland's book, Practical Python, for some 
> time now. For some time something has struck me. Is there such an object as 
> an ARRAY in the Python language.

An array is a low-level construct that you hardly ever need. So it's hidden
away in the array *module*.

What you most probably want is a list type, that can hold an arbitrary number
of elements. This one is part of core Python. You use it like this:

l1 = [3, 4, 5]  # A list of integers
l2 = ["s1", "s2"] # A list of strings
l_misc = [3, 5.0, "asdfsdf"] # A list of misc. stuff

print l1[0]     # print first list element
l1.append(6)    # append another element to the list

etc. Have a look at the methods lists support in order to learn how to use
them. They're a little hard to find, because they're hidden here:
http://www.python.org/doc/current/lib/typesseq-mutable.html

Uhm. Better read your tutorial than this. I hardly understand it myself ;-)

-- Gerhard




More information about the Python-list mailing list