The syntax is:

a[start:stop]  # items start through stop-1
a[start:]      # items start through the rest of the array
a[:stop]       # items from the beginning through stop-1
a[:]           # a copy of the whole array

There is also the step value, which can be used with any of the above:

a[start:stop:step] # start through not past stop, by step

The key point to remember is that the :stop value represents the first value that is not in the selected slice. So, the difference between stop and start is the number of elements selected (if step is 1, the default).

The other feature is that start or stop may be a negative number, which means it counts from the end of the array instead of the beginning. So:

a[-1]    # last item in the array
a[-2:]   # last two items in the array
a[:-2]   # everything except the last two items

Similarly, step may be a negative number:

a[::-1]    # all items in the array, reversed
a[1::-1]   # the first two items, reversed
a[:-3:-1]  # the last two items, reversed
a[-3::-1]  # everything except the last two items, reversed

Python is kind to the programmer if there are fewer items than you ask for. For example, if you ask for a[:-2] and a only contains one element, you get an empty list instead of an error. Sometimes you would prefer the error, so you have to be aware that this may happen.

Relationship with the slice object

A slice object can represent a slicing operation, i.e.:

a[start:stop:step]

is equivalent to:

a[slice(start, stop, step)]

Slice objects also behave slightly differently depending on the number of arguments, similar to range(), i.e. both slice(stop) and slice(start, stop[, step]) are supported. To skip specifying a given argument, one might use None, so that e.g. a[start:] is equivalent to a[slice(start, None)] or a[::-1] is equivalent to a[slice(None, None, -1)].

While the :-based notation is very helpful for simple slicing, the explicit use of slice() objects simplifies the programmatic generation of slicing.

Answer from Greg Hewgill on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-slicing
Python List Slicing - GeeksforGeeks
In Python, list slicing allows out-of-bound indexing without raising errors. If we specify indices beyond the list length then it will simply return the available items. Example: The slice a[7:15] starts at index 7 and attempts to reach index ...
Published   July 23, 2025
🌐
W3Schools
w3schools.com › python › ref_func_slice.asp
Python slice() Function
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... Create a tuple and a slice object.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › brackets › slicing.html
[] (slicing) — Python Reference (The Right Way) 0.1 documentation
>>> +---+---+---+---+ >>> |-4 |-3 |-2 |-1 | <= negative indexes >>> +---+---+---+---+ >>> | A | B | C | D | <= sequence elements >>> +---+---+---+---+ >>> | 0 | 1 | 2 | 3 | <= positive indexes >>> +---+---+---+---+ >>> |<- 0:3:1 ->| <= extent of the slice: "ABCD"[0:3:1]
Top answer
1 of 16
6664

The syntax is:

a[start:stop]  # items start through stop-1
a[start:]      # items start through the rest of the array
a[:stop]       # items from the beginning through stop-1
a[:]           # a copy of the whole array

There is also the step value, which can be used with any of the above:

a[start:stop:step] # start through not past stop, by step

The key point to remember is that the :stop value represents the first value that is not in the selected slice. So, the difference between stop and start is the number of elements selected (if step is 1, the default).

The other feature is that start or stop may be a negative number, which means it counts from the end of the array instead of the beginning. So:

a[-1]    # last item in the array
a[-2:]   # last two items in the array
a[:-2]   # everything except the last two items

Similarly, step may be a negative number:

a[::-1]    # all items in the array, reversed
a[1::-1]   # the first two items, reversed
a[:-3:-1]  # the last two items, reversed
a[-3::-1]  # everything except the last two items, reversed

Python is kind to the programmer if there are fewer items than you ask for. For example, if you ask for a[:-2] and a only contains one element, you get an empty list instead of an error. Sometimes you would prefer the error, so you have to be aware that this may happen.

Relationship with the slice object

A slice object can represent a slicing operation, i.e.:

a[start:stop:step]

is equivalent to:

a[slice(start, stop, step)]

Slice objects also behave slightly differently depending on the number of arguments, similar to range(), i.e. both slice(stop) and slice(start, stop[, step]) are supported. To skip specifying a given argument, one might use None, so that e.g. a[start:] is equivalent to a[slice(start, None)] or a[::-1] is equivalent to a[slice(None, None, -1)].

While the :-based notation is very helpful for simple slicing, the explicit use of slice() objects simplifies the programmatic generation of slicing.

2 of 16
728

The Python tutorial talks about it (scroll down a bit until you get to the part about slicing).

The ASCII art diagram is helpful too for remembering how slices work:

 +---+---+---+---+---+---+
 | P | y | t | h | o | n |
 +---+---+---+---+---+---+
   0   1   2   3   4   5
  -6  -5  -4  -3  -2  -1

One way to remember how slices work is to think of the indices as pointing between characters, with the left edge of the first character numbered 0. Then the right edge of the last character of a string of n characters has index n.

🌐
University of Pittsburgh
sites.pitt.edu › ~naraehan › python3 › mbb8.html
Python 3 Notes: List Slicing
Python 3 Notes [ HOME | LING 1330/2330 ] Tutorial 8: List Slicing << Previous Tutorial Next Tutorial >> On this page: slice indexing with [:], negative indexing, slice and negative indexing on strings. Video Tutorial Python 3 Changes print(x,y) instead of print x, y Python 2 vs.
🌐
Note.nkmk.me
note.nkmk.me › home › python
How to Slice a List, String, and Tuple in Python | note.nkmk.me
May 6, 2023 - One way to remember how slices ... — Python 3.11.3 documentation · +---+---+---+---+---+---+ | P | y | t | h | o | n | +---+---+---+---+---+---+ 0 1 2 3 4 5 6 -6 -5 -4 -3 -2 -1 · This example demonstrates slices for strings, but the same concept applies to lists, tuples, and ...
🌐
Medium
medium.com › @pies052022 › what-is-list-slicing-python-how-it-works-with-examples-a20ad4a0036a
What is List Slicing Python? How it Works With Examples | by JOKEN VILLANUEVA | Medium
February 26, 2026 - While slicing is getting a subset of elements from an iterable based on their indexes. The slice() function returns an object of type slice. A slice object specifies how to divide a sequence. You can determine where the slicing begins and ends. You can optionally specify the step that permits only every other item to be sliced. In Python, list slicing is a widespread practice, and it is the method most frequently employed by programmers to solve problems efficiently...
🌐
Learn By Example
learnbyexample.org › python-list-slicing
Python List Slicing - Learn By Example
June 20, 2024 - This syntax involves specifying the starting index (where your slice begins), the stopping index (where it ends), and the step size (how many elements you skip between each included element). With this simple technique, you can access elements from the beginning, middle, or end of a list, modify, remove, or insert elements in a list, and even create copies of entire lists.
Find elsewhere
🌐
DataCamp
datacamp.com › tutorial › python-slice
Python Slice: Useful Methods for Everyday Coding | DataCamp
January 15, 2025 - Python’s slice() function provides an alternative definition of slicing parameters as reusable slice objects. These objects encapsulate slicing logic and can be applied across multiple sequences. ... # Create a slice object slice_obj = slice(1, 4) # Apply to a list numbers = [10, 20, 30, 40, 50] print(numbers[slice_obj]) # Output: [20, 30, 40] # Apply to a string text = "Python" print(text[slice_obj]) # Output: "yth"
🌐
Kansas State University
textbooks.cs.ksu.edu › intro-python › 07-lists › 05-slicing-lists
Slicing Lists :: Introduction to Python
June 27, 2024 - Resources Slides One of the coolest features in Python is the ability to easily create slices of lists. A slice is simply a portion of a list that can be stored and used as a separate list, allowing us as programmers to quickly create and manipulate new lists based on existing lists.
🌐
Unstop
unstop.com › home › blog › python list slice | syntax, parameters & uses (+code examples)
Python List Slice | Syntax, Parameters & Uses (+Code Examples)
December 30, 2024 - Python list slice technique extracts portions of a list using indices. Its parameters list[start:stop:step], offers flexibility to select specific elements.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › list slicing in python
List Slicing in Python
November 11, 2024 - Python List Slicing is a technique for extracting specific portions of a list. The syntax for list slicing is: Lst: The list you want to slice.
🌐
Python Morsels
pythonmorsels.com › slicing
List slicing in Python - Python Morsels
March 8, 2024 - Let's talk about slicing lists in Python. Let's say we have a fruits variable that points to a list: >>> fruits = ['watermelon', 'apple', 'lime', 'kiwi', 'pear', 'lemon', 'orange'] >>> fruits ['watermelon', 'apple', 'lime', 'kiwi', 'pear', 'lemon', 'orange'] ... If we put a colon and another number inside the square brackets, we'll slice this list instead of indexing it:
🌐
Real Python
realpython.com › ref › glossary › slicing
slicing | Python Glossary – Real Python
In Python, slicing is an operation that allows you to extract portions of sequences like lists, tuples, and strings by specifying a start, stop, and step indices with the syntax sequence[start:stop:step]. In this syntax, start is the index where ...
🌐
Medium
medium.com › @nbagrat › mastering-python-lists-slicing-4e86e62f2d70
Mastering Python Lists: Slicing. Slicing a list is an easy way to access… | by nbagrat | Medium
November 14, 2025 - +--------------+------------------------------------------------+---------------+------------------------------------+---------+ | Rule | Meaning | Example Slice | How It Works | Output | +--------------+------------------------------------------------+---------------+------------------------------------+---------+ | start | Index where slicing begins | `s[1:4:1]` | Begin at index 1 (`'B'`) | `"BCD"` | +--------------+------------------------------------------------+---------------+------------------------------------+---------+ | stop | Index just past where slicing ends (exclusive) | `s[1:4:
🌐
Python
docs.python.org › 2.3 › whatsnew › section-slices.html
15 Extended Slices
July 4, 2010 - However, Python's built-in list, tuple, and string sequence types have never supported this feature, raising a TypeError if you tried it. Michael Hudson contributed a patch to fix this shortcoming. For example, you can now easily extract the elements of a list that have even indexes: ... If you have a mutable sequence such as a list or an array you can assign to or delete an extended slice, but there are some differences between assignment to extended and regular slices.
🌐
Programiz
programiz.com › python-programming › methods › built-in › slice
Python slice()
slice_object = slice(-1, -4, -1) print(py_list[slice_object]) # ['n', 'o', 'h'] # contains indices -1 and -3 · slice_object = slice(-1, -5, -2) print(py_tuple[slice_object]) # ('n', 'h') ... The slice object can be substituted with the indexing syntax in Python.
Top answer
1 of 3
35

Ellipsis is used mainly by the numeric python extension, which adds a multidimensional array type. Since there are more than one dimensions, slicing becomes more complex than just a start and stop index; it is useful to be able to slice in multiple dimensions as well. eg, given a 4x4 array, the top left area would be defined by the slice "[:2,:2]"

>>> a
array([[ 1,  2,  3,  4],
       [ 5,  6,  7,  8],
       [ 9, 10, 11, 12],
       [13, 14, 15, 16]])

>>> a[:2,:2]  # top left
array([[1, 2],
       [5, 6]])

Ellipsis is used here to indicate a placeholder for the rest of the array dimensions not specified. Think of it as indicating the full slice [:] for dimensions not specified, so for a 3d array, a[...,0] is the same as a[:,:,0] and for 4d, a[:,:,:,0].

Note that the actual Ellipsis literal (...) is not usable outside the slice syntax in python2, though there is a builtin Ellipsis object. This is what is meant by "The conversion of an ellipsis slice item is the built-in Ellipsis object." ie. "a[...]" is effectively sugar for "a[Ellipsis]". In python3, ... denotes Ellipsis anywhere, so you can write:

>>> ...
Ellipsis

If you're not using numpy, you can pretty much ignore all mention of Ellipsis. None of the builtin types use it, so really all you have to care about is that lists get passed a single slice object, that contains "start","stop" and "step" members. ie:

l[start:stop:step]   # proper_slice syntax from the docs you quote.

is equivalent to calling:

l.__getitem__(slice(start, stop, step))
2 of 3
27

Defining simple test class that just prints what is being passed:

>>> class TestGetitem(object):
...   def __getitem__(self, item):
...     print type(item), item
... 
>>> t = TestGetitem()

Expression example:

>>> t[1]
<type 'int'> 1
>>> t[3-2]
<type 'int'> 1
>>> t['test']
<type 'str'> test
>>> t[t]
<class '__main__.TestGetitem'> <__main__.TestGetitem object at 0xb7e9bc4c>

Slice example:

>>> t[1:2]
<type 'slice'> slice(1, 2, None)
>>> t[1:'this':t]
<type 'slice'> slice(1, 'this', <__main__.TestGetitem object at 0xb7e9bc4c>)

Ellipsis example:

>>> t[...]
<type 'ellipsis'> Ellipsis

Tuple with ellipsis and slice:

>>> t[...,1:]
<type 'tuple'> (Ellipsis, slice(1, None, None))
🌐
The Python Coding Stack
thepythoncodingstack.com › the python coding stack › a slicing story
A Slicing Story - by Stephen Gruppetta
June 25, 2024 - You can read more about __getitem__() in The Manor House, the Oak-Panelled Library, the Vending Machine, and Python's `__getitem__()`. In this new class called TestList, which inherits from list, you first print the value and data type of the argument in the __getitem__() method, and then you call the list's __getitem__() method and return its value. This is what super().__getitem__(item) does since list is the superclass for TestList. The syntax 2:7 within the square brackets represents a slice object.