Newbie question about reference
Terry Reedy
tjreedy at udel.edu
Sat Mar 22 17:07:32 EST 2003
"Tim Smith" <tssmith at velocio.com> wrote in message
news:a5jp7v4n254bu0j4nnu16sevll3qeiaglp at 4ax.com...
> Something that this beginner does not understand about Python.
correct ;-)
> Why does the following--
>
> > python
> Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more
> information.
> >>> x = 1
> >>> y = 2
> >>> z = 3
> >>> list = [x, y, z]
You here bind 'list' to the object [1,2,3]. (Note: DON'T use builtin
names as vars unless you have a positive reason for so doing.)
> >>> list
> [1, 2, 3]
> >>> y = 0
You here rebind the name 'y' to the value 0. Neither has nothing to
do with 'list'
> >>> list
> [1, 2, 3[
>
> do what it does? I expected the last "list" to return [1, 0, 3].
This is almost funny. More ofter, newbies do something like the
following
a = b= [0,1]
a[0]=2
and then wonder why b[0] is 2 rather than 0.
Terry J. Reedy
More information about the Python-list
mailing list