/
🍣

Python slicing

Python
sample_list = [0,1,2,3,4,5,6,7,8,9]

# First item
sample_list[0]

# Last item
sample_list[-1]

# First 3 items
sample_list[:3]

# Last 3 items
sample_list[-3:]

# A copy of the list
sample_list[:]

# A copy of the list without first item
sample_list[1:]

# A copy of the list without last item
sample_list[:-1]
Edit this page
Code Snippets & Notes by Makzan