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))
Answer from Brian on Stack Overflow
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › brackets › slicing.html
[] (slicing) — Python Reference (The Right Way) 0.1 documentation
>>> # when using extended slice syntax both chunks must match >>> l = [0, 1, 2, 3] >>> l[::2] = "ABCD" Traceback (most recent call last): File "<interactive input>", line 1, in <module> ValueError: attempt to assign sequence of size 4 to extended slice of size 2
🌐
Python
docs.python.org › 3 › c-api › slice.html
Slice Objects — Python 3.14.3 documentation
3.14.3 Documentation » · Python/C API reference manual » · Concrete Objects Layer » · Slice Objects · | Theme · Auto · Light · Dark | PyTypeObject PySlice_Type¶ · Part of the Stable ABI. The type object for slice objects. This is the same as slice in the Python layer.
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))
🌐
W3Schools
w3schools.com › python › python_strings_slicing.asp
Python - Slicing Strings
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... You can return a range of characters by using the slice syntax.
🌐
W3Schools
w3schools.com › python › ref_func_slice.asp
Python slice() Function
Start the slice object at position 3, and slice to position 5, and return the result:
🌐
DataCamp
datacamp.com › tutorial › python-slice
Python Slice: Useful Methods for Everyday Coding | DataCamp
January 15, 2025 - Slicing in Python is a method for extracting specific portions of sequences like strings, lists, tuples, and ranges. Slicing can refer to using the built-in slice() function or the even more common bracket notation that looks like this: [start:end:step]. The functionality is a core part of ...
🌐
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
🌐
Programiz
programiz.com › python-programming › methods › built-in › slice
Python slice()
Become a certified Python programmer. Try Programiz PRO! ... The slice() function returns a slice object that is used to slice any sequence (string, tuple, list, range, or bytes).
Find elsewhere
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › slice.html
slice — Python Reference (The Right Way) 0.1 documentation
Slice objects have read-only data attributes start, stop and step which merely return the argument values (or their default). They have no other explicit functionality; however they are used by Numerical Python and other third party extensions. Slice objects are also generated when extended ...
🌐
Python documentation
docs.python.org › 3 › tutorial › introduction.html
3. An Informal Introduction to Python — Python 3.14.3 documentation
The first row of numbers gives the position of the indices 0…6 in the string; the second row gives the corresponding negative indices. The slice from i to j consists of all characters between the edges labeled i and j, respectively.
🌐
Quansight-labs
quansight-labs.github.io › ndindex › indexing-guide › slices.html
Slices - ndindex documentation
By using a slice that selects a single element instead of an integer index, you can avoid IndexError when the index is out of bounds. For example, suppose you want to implement a quick script with a rudimentary optional command line argument (without the hassle of argparse). This can be done by manually parsing sys.argv, which is a list of the arguments of passed at the command line, including the filename. For example, python script.py arg1 arg2 would have sys.argv == ['script.py', 'arg1', 'arg2']. Suppose you want your script to do something special if it called as myscript.py help.
🌐
Python
docs.python.org › 2.3 › whatsnew › section-slices.html
https://docs.python.org/2.3/whatsnew/section-slice...
To simplify implementing sequences that support extended slicing, slice objects now have a method indices(length) which, given the length of a sequence, returns a (start, stop, step) tuple that can be passed directly to range(). indices() handles omitted and out-of-bounds indices in a manner consistent with regular slices (and this innocuous phrase hides a welter of confusing details!).
Top answer
1 of 16
6657

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.

🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
Return a slice object representing the set of indices specified by range(start, stop, step).
🌐
Codecademy
codecademy.com › docs › python › built-in functions › slice()
Python | Built-in Functions | slice() | Codecademy
September 26, 2025 - The slice() function creates a slice object that specifies how to slice sequences like strings, lists, tuples, and ranges. It provides a way to extract specific portions of sequences by defining the start, stop, and step parameters, offering ...
🌐
O’Reilly Media
oreilly.com › o'reilly › radar › how do i use the slice notation in python?
How do I use the slice notation in Python?
February 19, 2020 - Extended indexing syntax used for slicing is aList[start:stop:step]. The start argument and the step argument both default to none – the only required argument is stop. Did you notice this is similar to how range was used to define lists A and B? This is because the slice object represents the set of indices specified by range(start, stop, step). Python 3.4 documentation
🌐
Reddit
reddit.com › r/python › a comprehensive guide to slicing in python
r/Python on Reddit: A Comprehensive Guide to Slicing in Python
February 1, 2022 - I can relate to this! I also use `[...][...]` (two-slice) notation most of the time for these cases.
🌐
Simplilearn
simplilearn.com › home › resources › software development › your ultimate python tutorial for beginners › everything you need to know about python slicing
Everything You Need to Know About Python Slicing
January 26, 2025 - Python is a widely used, general-purpose programming language. So what is slicing and negative indices? Learn all about Python slicing, index, & more. Read On!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
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 ...