Do me a favor, take a few seconds to have a look at my last project.

Thank you, Lulu

Slice lists in Python

Get sublist

>>> myList=[10,20,30,40,50]
>>> myList[1:4]
[20, 30, 40]

Get sublist from the beginning

>>> myList=[10,20,30,40,50]
>>> myList[:2]
[10, 20]

Get sublist from the end

>>> myList=[10,20,30,40,50]
>>> myList[-3:]
[30, 40, 50]

See also


Last update : 04/13/2019