How do I ignitalize a list please?

Kevin Cazabon kcazabon at home.com
Wed May 3 06:51:16 CEST 2000


This is covered very well (as well as most other aspects of Python) in the
documentation, specifically the Tutorial.

However, in brief, you simply need to create the empty list first, as
follows:

list = []

list.append("spam")

for i in range(42):
    list.append(i * 42)

i[12] = "Eggs"

>>>i[12]
Eggs

###############

However, if you simply say that list=[], you cannot then assign to list[12]
because it doesn't exist yet.  You have to append X number of objects to the
list, or create the list with that many elements in the first place using a
"range" loop.

Kevin.
<cmfinlay at SPAMmagnet.com.au> wrote in message
news:kSUtN6=fLIxjJNG0pGTq25a0tuiY at 4ax.com...
> How do I initialize a 'list' please?
> I read that a list is the only array that can be modified in standard
> python.
>
> (to put it simply)
>
> i = 1
> mags[0] = 0
> mags[1] = 1
> print mags[i]
>
> doesn't work.
>
> Please reply here
> or at cmfinlaySPAM at magnet.com.au





More information about the Python-list mailing list