[Tutor] List weirdness
alan.gauld at btinternet.com
Fri Feb 13 09:47:06 CET 2009
"Moos Heintzen" <iwasroot at gmail.com> wrote
> >>> d = []
> >>> d=1
> IndexError: list assignment index out of range
> >>> d.append(1)
> >>> d
> I guess I can't reference  on an empty list.
Thats right. You can't assign a value to a position in
a list that hasn't been created yet. It has nothing to
do with nesting, its the same for a simople lust:
>>> lst = 
>>> lst = 66
Traceback (most recent call last):
File "<input>", line 1, in <module>
IndexError: list assignment index out of range
You can also use insert, which takes an index.
But if the index is non existent it appends...
>>> lst2 = 
Author of the Learn to Program web site
More information about the Tutor