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
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_slicing.asp
NumPy Array Slicing
Slicing in python means taking elements from one given index to another given index. We pass slice instead of index like this: [start:end]. We can also define the step, like this: [start:end:step]. ... Note: The result includes the start index, ...
Top answer
1 of 16
6665

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
729

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.

🌐
Pythonhealthdatascience
pythonhealthdatascience.com › content › 01_algorithms › 03_numpy › 03_slicing.html
Array slicing and indexing — Python for health data science.
Going back to slicing we can understand the dimensions. Here’s a reminder fo the full array: ... Task: slice td so that we have the vector [13, 23, 33] i.e. the [i, 1, 0] elements where i is the row.
🌐
The Python Coding Stack
thepythoncodingstack.com › the python coding stack › a slicing story
A Slicing Story - by Stephen Gruppetta
June 25, 2024 - Slices create copies when dealing with lists, strings, tuples, and other built-in data types. However, this behaviour is not guaranteed by slicing, as you've seen in the case of NumPy arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-slicing
Python List Slicing - GeeksforGeeks
Explanation: slice fruits[2:5] starts from index 2 ("Orange") and ends before index 5, so it returns ["Orange", "Mango", "Grapes"]. The original list remains unchanged.
Published: July 16, 2026
🌐
Nanyang Technological University
libguides.ntu.edu.sg › python › arrayslicing
NP.4 Array Slicing - Python for Basic Data Analysis - LibGuides at Nanyang Technological University
2 weeks ago - Array slicing is similar to list slicing in Python. Array indexing also begins from 0. However, since arrays can be multidimensional, we have to specify the slice for each dimension. As we are mainly working with 2 dimensional arrays in this guide, we need to specify the row and column like what we do in a matrix.
🌐
freeCodeCamp
freecodecamp.org › news › python-slicing-how-to-slice-an-array
Python Slicing – How to Slice an Array and What Does [::-1] Mean?
December 8, 2022 - In this article, we've briefly looked at how to declare arrays in Python, how to access values in an array, and also how to cut – or slice – a part of an array using a colon and square brackets.
Find elsewhere
🌐
Railsware
railsware.com › home › engineering › indexing and slicing for lists, tuples, strings, other sequential types in python
Python Indexing and Slicing for Lists, Tuples, Strings, other Sequential Types | Railsware Blog
January 22, 2025 - Python supports slice notation for any sequential data type like lists, strings, tuples, bytes, bytearrays, and ranges. Also, any new data structure can add its support as well. This is greatly used (and abused) in NumPy and Pandas libraries, which are so popular in Machine Learning and Data Science.
🌐
StrataScratch
stratascratch.com › blog › numpy-array-slicing-in-python
NumPy Array Slicing in Python - StrataScratch
March 1, 2024 - You specify the start, stop, and step within square brackets to select a portion of the array. ... The first slice arr[:5] selects the first five elements of the array, demonstrating how omitting the start index defaults to 0.
🌐
Python.org
discuss.python.org › ideas
Array slicing notation to get N elements from index I - Ideas - Discussions on Python.org
April 24, 2023 - Hi - my first post here 🙂 I’ve had a search through PEPs, forums, and at work but haven’t been able to prove the negative that this syntactic sugar doesn’t exist. Frequently I need to get an array slice in the form: arr[start_idx:(start_idx + some_length)] The repetition of the start_idx ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-slicing-multi-dimensional-arrays
Python Slicing Multi-Dimensional Arrays - GeeksforGeeks
July 1, 2026 - This produces a new 2-D array containing the last column values from every matrix. Slices can be used not only for reading data but also for updating multiple values at once. Python · import numpy as np matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) matrix[0:2, 0:2] = 0 print(matrix) Output ·
🌐
DataCamp
datacamp.com › doc › numpy › array-slicing
NumPy Array Slicing
Array slicing is utilized when ... slicing syntax follows the format array[start:stop:step], where start is the index to begin the slice, stop is the index to end the slice (exclusive), and step defines the interval between elements....
🌐
Sentry
sentry.io › sentry answers › python › python slice notation
Python slice notation | Sentry
October 21, 2022 - Since in Python, strings are arrays, we can use the same syntax for both object types. Slicing segments an array and returns that segment. In the example below, a string is segmented to return a single word from within the string: hello_world_string = "Hello World!" world = hello_world_string[7:12] print(world) ... The start is the index of the array that you would like the slice to begin with, the stop is the index of the array you would like to stop at.
🌐
YouTube
youtube.com › watch
Slicing in NumPy is easy! ✂️ - YouTube
#coding #numpy #python Slicing in NumPy allows you to extract portions of an array using a [start:stop:step] syntax. It works similarly to Python lists but ...
Published: July 27, 2025
🌐
GeeksforGeeks
geeksforgeeks.org › python › slice-a-2d-array-in-python
Slice a 2D Array in Python - GeeksforGeeks
July 23, 2025 - In this example, np.split() is used with the axis=1 parameter to split the 2D array along the columns. The second argument [1, 2] specifies the indices at which the array should be split. The resulting slices are stored in the slices variable.
🌐
Medium
wbuchmueller.medium.com › numpys-indexing-and-slicing-notation-explained-visually-67dc981c22c1
Numpy’s indexing and slicing notation explained visually | by Wilhelm Buchmüller | Medium
June 23, 2018 - What happens if we put a slice into there ? To reiterate, a slice is special kind of index notation where you can specify, that you want to access more than index from the array. The visualization to python’s indexing for one-dimensional lists/arrays is the following:
🌐
YouTube
youtube.com › deeecode the web
How to Slice an Array in Python, with examples - YouTube
In this video, I simplify how to slice an array using different examples that shows the different ways arrays can be sliced in Python.Timestamp:00:00 Making ...
Published: December 9, 2022
Views: 328
🌐
Lkhibra
lkhibra.ma › books › Python-for-Data-Analysis.pdf pdf
Python for Data Analysis Data Wrangling with pandas, NumPy & Jupyter
Python · for Data Analysis · Data Wrangling with pandas, NumPy & Jupyter · Wes McKinney · Third · Edition
🌐
Earth Data Science
earthdatascience.org › home
Slice (or Select) Data From Numpy Arrays | Earth Data Science - Earth Lab
September 23, 2019 - Use indexing to slice (i.e. select) data from one-dimensional and two-dimensional numpy arrays. In a previous chapter that introduced Python lists, you learned that Python indexing begins with [0], and that you can use indexing to query the value of items within Python lists.