Python: Slice Notation on List

python_tutorials

Introduction

The term slicing in programming usually refers to obtaining a substring, sub-tuple, or sublist from a string, tuple, or list respectively.

Python offers an array of straightforward ways to slice not only these three but any iterable. An iterable is, as the name suggests, any object that can be iterated over.

In this article, we’ll go over everything you need to know about Slicing Lists in Python.

Slicing a List in Python

There are a couple of ways to slice a list, most common of which is by using the : operator with the following syntax:

a_list[start:end]
a_list[start:end:step]

The start parameter represents the starting index, end is the ending index, and step is the number of items that are “stepped” over.

If step isn’t explicitly given, the default value is 1. Note that the item with the index start will be included in the

 

 

To finish reading, please visit source site