[Tutor] Re: Erik's questions
Charlie Clark
charlie@begeistert.org
Sun, 14 Apr 2002 00:39:23 +0200
On 2002-04-13 at 18:00:05 [+0200], tutor-request@python.org wrote:
> site_url = []
>
> but I thought that it was possible to just jump in and start assigning
> directly to elements in a list. I can't -- even if I declare site_url as
> a list, the following doesn't work:
>
> >>> site_url=[]
> >>> site_url[0] = 'hi'
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> IndexError: list assignment index out of range
>
> Why is that? I thought dynamic typing was more flexible than this... ?
This is not a typing issue.
site_url exists but as it doesn't have any members (it's an empty list), site_url[0] returns an error and cannot be assigned: there is no one in the dinner queue to get the first tray.
Charlie