[Tutor] Static Variable in Functions

Alan Gauld alan.gauld at btinternet.com
Mon Mar 14 09:56:50 CET 2011

"Yasar Arabaci" <yasar11732 at gmail.com> wrote

> >>> a=["a"]
> >>> b=[a]
> >>> a.append("c")
> >>> b
> [['a', 'c']]
> Apperantly, I can change something (which is mutable) inside  a list 
> without even touching the list itself :)

But the point is that you *are* touching the list.
In this case you have two names referring to the same list.
You can modify that list (because it is mutable) via either name, it
makes no difference because they both refer to the same list.

So a.append() is exactly the same operation as b.append()


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list