capypad
0 day streak
python / beginner
Snippet

Accessing Parts of a List (Slicing)

Slicing allows you to create a new list by extracting a portion of an existing list using a start and end index.

snippet.py
python
1
2
3
numbers = [10, 20, 30, 40, 50]
subset = numbers[1:4]
print(subset)
Breakdown
1
numbers[1:4]
Extracts elements from index 1 (inclusive) to index 4 (exclusive), resulting in [20, 30, 40].