Slicing

noun

say it: “SLY-sing” /ˈslaɪsɪŋ/

Taking a piece of a list or string by its positions, written [start:stop]; the item at the stop position isn't included.

What is slicing?

Slicing takes a piece of a list or string with [start:stop]. The stop position is not included.

top_scores = [98, 91, 87, 80, 75]
print(top_scores[0:3])  # [98, 91, 87]
print("Saturday"[0:3])  # Sat

In a sentence

  • “Slicing the scores with [0:3] gave the top three.”
  • “"Saturday"[0:3] uses slicing to get "Sat".”

Level: Apprentice · More Python terms at this level

Updated