Thanks, Ryan, for detailed explanation;
I'm learning Python now, too, so I don't know exactly how stuff works.
[]'s
Douglas
On Mon, Jun 30, 2008 at 18:33, Lie Ryan <[EMAIL PROTECTED]> wrote:
>> You can do it with slice assignment too:
>> >>> a = [1, 2, 3, 4]
>> >>> a[1:3] = [[7, 8]]
>> >>> a
>
> But if you don't have l1 defined yet, you can't add to l2
> It's like:
> def a2():
> l1 = foo + l2
>
> UnboundLocalError: local variable 'foo' referenced before assignment
>
> It's because l1 (and foo at above example) is a local variable.
> a1's l1 is different from a2's l1.
>
>
> Sorr
In a2() you do l1 += l2, ie, l1 = l1 + l2
But if you don't have l1 defined yet, you can't add to l2
It's like:
def a2():
l1 = foo + l2
UnboundLocalError: local variable 'foo' referenced before assignment
It's because l1 (and foo at above example) is a local variable.
a1's l1 is different
>
> >>> s = [1,2,3]
> >>> x = 5
> >>> s[len(s):len(s)] = [x] # (1)
>
>>> s
[1, 2, 3, 5]
When you did s[len(s):len(s)] you got the slice begining at len(s) with end
at len(s) - 1, ie, nothing.
At step (1), len(s) = 3, so you did s[3:3] = [x]. It meant that the slice
starting at index