list.append problem?

Emile van Sebille emile at fenx.com
Tue Oct 2 08:43:28 EDT 2001


You've rebound a to a different object in the second line.

--

Emile van Sebille
emile at fenx.com

---------
"Bob Parnes" <rparnes at megalink.net> wrote in message
news:trjcuqh5bdrs89 at corp.supernews.com...
<snip>
> As another newcomer I discovered this on my own. What is confusing, I
> think, is that it seems to apply only to empty objects. For example
>
> >>> a = b = [1, 2. 3]
> >>> a = [4, 5, 6]
> >>> b
> [1, 2, 3]
> >>> a.append(7)
> >>> a
> [4, 5, 6, 7]
> >>> b
> [1, 2, 3]
>
> In this case a and b are not bound to the same object. It seems to me that
> python treats empty objects differently from assigned objects. Or
something
> like that, I'm probably not articulating it well.
>
> --
> Bob Parnes
> rparnes at megalink.net




More information about the Python-list mailing list