references/addrresses in imperative languages

Xah Lee xah at xahlee.org
Tue Jun 21 08:30:40 CEST 2005


Dear Andrea Griffini,

Thanks for explaning this tricky underneath stuff.

 Xah
 xah at xahlee.orghttp://xahlee.org/

Andrea Griffini wrote:
> On Sun, 19 Jun 2005 22:25:13 -0500, Terry Hancock
> <hancock at anansispaceworks.com> wrote:
>
> >> PS is there any difference between
> >> t=t+[li]
> >> t.append(li)
> >
> >No, but
>
> Yes, a big one. In the first you're creating a new list
> and binding the name t to it, in the second you're extending
> a list by adding one more element at the end.
> To see the difference:
>
>   >>> a = [1,2,3]
>   >>> b = a
>   >>> a = a + [4]
>   >>> print a
>   [1, 2, 3, 4]
>   >>> print b
>   [1, 2, 3]
>   >>>
>   >>> a = [1,2,3]
>   >>> b = a
>   >>> a.append(4)
>   >>> print a
>   [1, 2, 3, 4]
>   >>> print b
>   [1, 2, 3, 4]
>   >>>
> 
> Andrea




More information about the Python-list mailing list