semantics of [:]

Dave Angel davea at ieee.org
Fri Nov 20 20:08:23 CET 2009



Esmail wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">Diez B. 
> Roggisch wrote:
>> Esmail schrieb:
>>> Could someone help confirm/clarify the semantics of the [:] operator
>>> in Python?
>>>
>>> a = range(51,55)
>>>
>>> ############# 1 ##################
>>> b = a[:] # b receives a copy of a, but they are independent
>>  >
>>>
>>> <snip>
>
>
> Semi-aside, if I wanted to make local copy of a list sent to me as a
> parameter, which of these is the most appropriate to use (I don't want
> changes to change the original list sent).
>
> Thanks again.
>
>
(1) is most appropriate in that case.  In fact, unless there is other 
code mixed in  between, it's always the most appropriate.


DaveA



More information about the Python-list mailing list