GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

What is done by list[x::y] in Python?

asked Nov 24, 2015 by Gaurav

1 Answer

It slices

x[startAt:endBefore:skip]

if you use skip = 2, every other element the list beginning at startAt and ending at endBefore will be selected. [Remember: indices live BETWEEN list elements]

To see this, enter

x = range(100)

at the Python prompt. Then try these things

x[::2]
x[::3]
x[10:40:6]

and check the outcome

answered Nov 24, 2015 by Swanky
...