• + 8 comments

    RazyDave: The colon, inside an array index, can set up to 3 numbers/parameters:

    The first one is the "from" number (included), the second is the "to" number (excluded), and the third is the "pace".

    • a[::2] will retrieve all array items (since it does not set up any from or to, and set the "pace"), starting from index 0, incrementing the index two by two and accessing all even indexes (0,2,4,6, and so on).
    • s[1::2] will retrieve all array items, from index 1, incrementing the index two by two and accessing all odd indexes (1,3,5,7,9, and so on).