[docs] Little Tutorial Correction
Georg Brandl
georg at python.org
Thu Sep 22 10:29:37 CEST 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am 22.09.2011 10:12, schrieb Petersen, Eike:
> Hello,
>
> http://docs.python.org/tutorial/introduction.html#lists under this section
> I read across the following statement:
>
> ?All slice operations return a new list containing the requested elements.
> This means that the following slice returns a shallow copy of the list
> //a//:
>
>>>> a[:]?
>
> But as far as I know the behaviour of the [:] operator is on the contrary
> called deep copying, since the following will return different lists:
>
> A = [1,2,3] B =A[:] A[1]=3
Hi Eike,
Python does indeed to only a shallow copy, since it does not copy the objects
themselves. To see this, you can try something like this:
>>> a = [[1, 2], [3]] b = a[:] a[0][0] = 999 a[0]
[999, 2]
>>> b[0]
[999, 2]
cheers,
Georg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
iEYEARECAAYFAk568fEACgkQN9GcIYhpnLBc7wCeNwbMJfX391dx0yO56Wo1jMYi
PioAoIIgwYl4N2Od+s9ceH5WFFvFydX4
=3pMf
-----END PGP SIGNATURE-----
More information about the docs
mailing list