Code

slicing the list from i to j ( i and j are integers )

  • Syntax :
my_list[i:j]
  • Slicing the list from i to j provide elements in the list with index k such that i <= k < j .

  • If i or j is greater than length of the list then length of the list is taken.

  • If i is not mentioned or None, 0 is used.

  • If j is not mentioned or None, length of the list is used.

  • The sliced list will be empty if i is greater than or equal to j.

The examples shown below work with list named my_list containing the following items/elements 1, '1cademy', 12.59, True.

Image 0

0

0

Updated 2021-04-01

Tags

Python Programming Language

Data Science