List Slicing in Python


Access parts of a list using slicing.

Source Code

numbers = [0, 1, 2, 3, 4, 5]
# Get items from index 2 to 4
print(numbers[2:5])
# Get the last three items
print(numbers[-3:])
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments