Learn how to slice lists in Python and understand the syntax, behavior, and common use cases of list slicing.
Table of contents
Getting the first N elements from a listSlicing makes a new listThe start index is inclusive but the stop index is exclusiveDefault slice start/stop valuesWhy the stop index isn't included in slicesNegative indexes work tooOut-of-bounds slicing is allowedThe slice step valueSlicing works on all sequencesThe most common uses for slicing in PythonUse slicing to get "slices" of sequences in PythonSort: