What does x[:]=[4,5,6] mean?
Indirect Meowbot
meowbot at meowing.net
Sat Jun 2 13:54:16 EDT 2001
"Franz GEIGER" <fgeiger at datec.at> wrote:
> In site.py I saw
> sys.path[:] = L
> What does this mean? Why is the '[:]'? Why not simply
> sy.path = L ?
In a language like C you have to work a little bit harder to get a
pointer to something. In Python, you have to work a little bit harder
_not_ to get just a reference.
>>> meow = [1,2,3]
>>> woof = meow
>>> meow[0] = 42
>>> print meow, woof
[42, 2, 3] [42, 2, 3]
>>> # Ewww!
...
>>> meow = [1,2,3]
>>> woof[:] = meow
>>> meow[0] = 42
>>> print meow, woof
[42, 2, 3] [1, 2, 3]
>>> # Yay.
More information about the Python-list
mailing list