List Slicing for Sublists in Python


Extract sublists using slice notation [start:end:step].

Source Code

numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
even_numbers = numbers[::2]  # Start to end, step by 2
print(f"Even numbers: {even_numbers}")
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments