What is slicing in Python?

Last updated 3 weeks, 1 day ago | 20 views 75     5

Tags:- Python

Python | Slicing 

As the name suggests, ‘slicing’ is taking parts of sequences like lists, tuples, and strings.

Syntax for slicing is [start : stop : step]

  • The start is the starting index from where to slice a list or tuple
  • The stop is the ending index.
  • The step is the number of steps to jump.
  • The default value for start is 0, stop is the number of items, and step is 1.
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

print(numbers[1 : : 2])  

#output : [2, 4, 6, 8, 10]