Slicing

Syntax [x:y:z]:

  • x: start index
  • y: end index (exclusive)
  • z: take very nth element.
    • For example, if z = 1 it takes every elements
    • if z = 2 it takes every 2nd elements
    • if z is negative, it will take in reverse
elems = list(range(10))
print(elems[::-1]) # [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
print(elems[::-2]) # [9, 7, 5, 3, 1]