[Tutor] FYI

Pedro Diaz Jimenez pdiaz88@terra.es
Sat, 14 Apr 2001 05:32:38 +0200


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Just a note

On Saturday 14 April 2001 05:23, Pedro Diaz Jimenez wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Wow, I didn't know this:
>
> Python 1.5.2 (#0, Apr  3 2000, 14:46:48)  [GCC 2.95.2 20000313 (Debian
> GNU/Linux)] on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>
> >>> a=[1,2,3,4,5,6]
> >>> b=a
> >>> a.remove(3)
> >>> a
>
> [1, 2, 4, 5, 6]
>
> >>> b
>
> [1, 2, 4, 5, 6]
>
> >>> c=a[:]
> >>> a.remove(1)
> >>> a
>
> [2, 4, 5, 6]
>
> >>> b
>
> [2, 4, 5, 6]
>
> >>> c
>
> [1, 2, 4, 5, 6]
>
> >>> a={}
> >>> b=a
> >>> a[1]='1'
> >>> a
>
> {1: '1'}
>
> >>> b
>
> {1: '1'}
>
> >>> c=a[:]
^^^^^^^^^^
THIS WONT WORK (hey, they are dictionaries after all, but I had to try it :)
>
> Maybe I'm not the only that missed that part on the tutorial, so thats why
> I post this ;D
>
> Moral:  lists, dictionaries (and all other objects???) are copies by
> reference, be careful when you pass them to functions
>
> Cheers
> Pedro
> - --
>
> /*
>  * Pedro Diaz Jimenez
>  * pdiaz88@terra.es
>  * pdiaz@acm.asoc.fi.upm.es
>  *
>  * La sabiduria me persigue, pero yo soy mas rapido
>  */
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.4 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
>
> iD8DBQE618LGnu53feEYxlERAmbVAJ91ROLA1sgNnLUeA/1KBeMXGtW32ACg4RiQ
> GrwS/csYskS7OZ5rMIbxXGc=
> =RXKv
> -----END PGP SIGNATURE-----

- ----------------------------------------
Content-Type: application/pgp-keys; charset="iso-8859-1"; name="my pgp key"
Content-Transfer-Encoding: base64
Content-Description: 
- ----------------------------------------

- -- 

/*
 * Pedro Diaz Jimenez
 * pdiaz88@terra.es 
 * pdiaz@acm.asoc.fi.upm.es
 *
 * La sabiduria me persigue, pero yo soy mas rapido
 */
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE618TWnu53feEYxlERAr6NAJ9OgQoRtdFhPTBchmfL2MGDbwRj2ACfYJwD
CN/IUTHHtv/oIYLK7/I5bXM=
=izjV
-----END PGP SIGNATURE-----