Slicing Syntax
Multiple Choice Easy
Question
What does [1,2,3,4,5][1:4] return?
Hint
Slicing is [start:stop:step], stop is exclusive.
Explanation
[1,2,3,4,5][1:4] returns [2, 3, 4]. Slicing syntax is [start:stop:step] where start is inclusive and stop is exclusive. Index 1 is 2, index 3 is 4, so elements at indices 1, 2, 3 are [2, 3, 4]. Omitting start defaults to 0, omitting stop defaults to the end. Negative indices count from the 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.