List Slicing
Predict Output Easy
Question
What does this code print?
Code
a = [10, 20, 30, 40, 50]
print(a[::2])
Hint
Step 2 takes every other element.
Explanation
a[::2] slices with step 2: indices 0, 2, 4, giving [10, 30, 50]. The :: syntax means [start:stop:step] with defaults for start (0) and stop (end).
Related Resources
Related Lessons
- Lists
Learn Python lists.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.