is list always with reference ?
holger krekel
pyth at devel.trillke.net
Tue Aug 27 04:24:54 EDT 2002
quite black wrote:
>
> Hi,all~
>
> when we build up a list(for example named list1) and write this line:
>
> list2=list1
>
> So, list2 is reference with list1, alright ? What I want to know is if all modifications on list1 will affect list2 ? I say "All" here.
>
yes, they will. It often helps if you fire up the python commandline:
[hpk at cobra pythonics]$ python
Python 2.2.1 (#1, Aug 20 2002, 17:44:37)
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> list1=[1,2,3]
>>> list2=list1
>>> list1.append(4)
>>> list2
[1, 2, 3, 4]
>>>
cheers,
holger
More information about the Python-list
mailing list