Why does python behave so? (removing list items)
Jarek Zgoda
jzgoda at o2.usun.pl
Wed Mar 26 18:15:31 EDT 2008
Michał Bentkowski pisze:
> Why does python create a reference here, not just copy the variable?
Because Python works like that -- it uses names and values idiom. If you
change value, all names will be bound to the same changed value.
>>>> j=range(0,6)
>>>> k=j
>>>> del j[0]
>>>> j
> [1, 2, 3, 4, 5]
>>>> k
> [1, 2, 3, 4, 5]
>
> Shouldn't k remain the same?
No further comments on this.
--
Jarek Zgoda
http://zgodowie.org/
"We read Knuth so you don't have to" - Tim Peters
More information about the Python-list
mailing list