The colon ':' is used to return list items above, below or in between any
index numbers your provide. This is also known as index slicing. However
when you don't provide any index numbers it simply returns every item in
the list.

Usage eg.

>> testList = [0,1,2,3,4,5]
>> print testList[:]  # all items
[0,1,2,3,4,5]

>> print testList[3:]  #all above and including index 3
[3,4,5]

>> print testList[:3] # all below, but not including index 3
[0,1,2]

>> print testList[2:5] # returns indices  2,3 and 4, but not 5
[2,3,4]

You can also use negative numbers which will count back from the end of the
list.

>> print testList[-2] # returns 2nd to last item in the list
[4]

>> print testList[:-2] # returns items up to, but not including the 2nd to
last item.
[0,1,2,3]

Additionally, as Dorian pointed out, arrays is the list object itself, but
arrays[:] is the contents of the list object.

In your loop example the result is the same because both the arrays
and arrays[:]
return the entire list to be looped over.

For more information refer to this python documentation page. Both the
Stings and Lists subjects have many examples and explanations.
http://docs.python.org/2/tutorial/introduction.html#strings

Cheers


-Chad


On Fri, Mar 1, 2013 at 8:33 AM, Panupat Chongstitwattana <[email protected]
> wrote:

> for a in arrays:
> and
> for a in arrays[:]:
> seem to do exactly the same thing. Is there any difference made by the [:]
> ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to