Syntax question

Chris Rebert clp2 at rebertia.com
Wed Jun 2 13:56:15 EDT 2010


On Wed, Jun 2, 2010 at 10:40 AM, pmz <przemek.zawada at gmail.com> wrote:
> Dear Group,
>
> It's really rookie question, but I'm currently helping my wife in some
> python-cases, where I'm non-python developer and some of syntax-diffs
> make me a bit confused.
>
> Could anyone give some light on line, as following:
> "ds = d[:]"  ### where 'd' is an array
>
> Let me guess, is it a declaration of two-dimension array?

Nope; Python doesn't really have variable declarations.*
That line of code copies the list `d` ( `[]` is the slicing operator,
and the colon indicates the bounds are the entire list; this is a
Python idiom) and assigns the copy to the variable `ds`. Note that the
copying is shallow (i.e. not recursive, only 1 level deep).

*Well, almost: There are `global` and `nonlocal`, but they're only
needed to specify a variable's scope in certain circumstances when you
want to be able to assign to said variable.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list