The documentation implies this has a few useful properties:

word[:2]    # The first two characters
word[2:]    # Everything except the first two characters

Here’s a useful invariant of slice operations: s[:i] + s[i:] equals s.

For non-negative indices, the length of a slice is the difference of the indices, if both are within bounds. For example, the length of word[1:3] is 2.

I think we can assume that the range functions act the same for consistency.

Answer from Toomai on Stack Overflow
🌐
Data Dependence
datadependence.com › 2016 › 05 › python-sequence-slicing-guide
A Quick Guide to Slicing in Python – Become a Python Ninja
July 6, 2016 - For example if you choose the starting ... index 5 will not be included. One way to remember this is that the start point is inclusive and the end point is exclusive....
Discussions

Regarding list slicing: can anyone help me understand the reasoning behind inclusive vs. exclusive indexing with negative vs. non-negative integers?
[-1] refers to the last element, so list[0:-1] gives you all but the last element in the same exclusive manner as you saw with positive indices. More on reddit.com
🌐 r/learnpython
9
5
April 27, 2019
What is slicing in Python? - Python - Data Science Dojo Discussions
Slicing enables the extraction of a designated range of elements from arrays, lists, strings, or tuples using the syntax [start : stop : step]. Here, start denotes the beginning or starting index, stop indicates the ending index, and step determines the interval between elements in the specified ... More on discuss.datasciencedojo.com
🌐 discuss.datasciencedojo.com
1
0
November 9, 2022
slice - How slicing in Python works - Stack Overflow
The above part explains the core features on how slice works, and it will work on most occasions. However, there can be pitfalls you should watch out, and this part explains them. The very first thing that confuses Python learners is that an index can be negative! Don't panic: a negative index means count backwards. ... s[-5:] # Start at the 5th index from the end of array... More on stackoverflow.com
🌐 stackoverflow.com
Why slices work the way they are?
It makes sense with a bit of practice. You should think about them differently. It's not a direct access to an index. It's a range. # 0 1 2 3 <--- indices # a b c d # 0 1 2 3 4 <--- slicing # a b c d # so.... elements = ['a', 'b', 'c', 'd'] >>> elements[:3] ['a', 'b', 'c'] More on reddit.com
🌐 r/learnpython
61
136
September 10, 2020
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_slicing.asp
NumPy Array Slicing
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, but excludes the end index.
🌐
Reddit
reddit.com › r/learnpython › regarding list slicing: can anyone help me understand the reasoning behind inclusive vs. exclusive indexing with negative vs. non-negative integers?
r/learnpython on Reddit: Regarding list slicing: can anyone help me understand the reasoning behind inclusive vs. exclusive indexing with negative vs. non-negative integers?
April 27, 2019 -

Python beginner here, coming from a Matlab and R background... so there's been a bit of a hurdle for me when it comes to understanding indexing in Python.

My current brain fuck has to do with wrapping my head around indexing and list ranges/slicing. And no amount of Google-fu is helping me here.

Let's say I have a simple list:

list = ["a", "b", "c", "d"]

If I want to take a slice of the list, the end of the range is exclusive when using non-negative values:

print(list[0:1])
['a']

Not super intuitive given my background, but fine. I understand what's going on and generally why it happens.

What I don't understand is why the end of the range is inclusive when using negative indexing:

print(list[0:-1])
['a', 'b', 'c']

It seems that the slice should only include ['a', 'b']: given how Python indexes a range of non-negative values, I would expect the result to only give the list items up to (but not including) the penultimate item in the list.

What's the rationale behind an exclusive range for non-negative values but an inclusive range for negative values?

🌐
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 15, but since the list ends at index 8, so it will return only the available elements (i.e. [8,9]). Negative indexing is useful for accessing elements from the end of the list.
Published   July 23, 2025
🌐
StrataScratch
stratascratch.com › blog › numpy-array-slicing-in-python
NumPy Array Slicing in Python
March 1, 2024 - Slicing 1D arrays in NumPy is straightforward. 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.
🌐
Data Science Dojo
discuss.datasciencedojo.com › python
What is slicing in Python? - Python - Data Science Dojo Discussions
November 9, 2022 - Slicing enables the extraction of a designated range of elements from arrays, lists, strings, or tuples using the syntax [start : stop : step]. Here, start denotes the beginning or starting index, stop indicates the …
Find elsewhere
🌐
DataCamp
datacamp.com › tutorial › python-slice
Python Slice: Useful Methods for Everyday Coding | DataCamp
January 15, 2025 - The syntax is perfect for concise operations, while slice() is invaluable for reusable and dynamic slicing logic. Slicing isn’t limited to Python’s built-in data structures—it extends into powerful libraries like NumPy and pandas, which are indispensable for data manipulation. While the basic principles remain consistent, these libraries introduce additional slicing capabilities tailored to their data structures. NumPy arrays take slicing to the next level, offering powerful tools for manipulating large, multi-dimensional datasets.
🌐
Medium
medium.com › pythoneers › slicing-through-arrays-a-python-technical-interviews-e8012a888ea8
Slicing through Arrays : A Python Technical Interview | by AnalystHub | The Pythoneers | Medium
January 13, 2024 - Imagine you are invited into an interview session, and in front of you is this question. You are given 2 minutes to understand and provide the expected output with a clear and concise explanation of the code. a = arr.array('d', [1.1, 2.1, 3.1, 2.6, 7.8]) print(a[0:3]) This seemingly simple code snippet introduces the concept of array slicing. To successfully tackle this question, candidates need to understand the `array` module, slicing in Python, and how to interpret the output.
🌐
freeCodeCamp
freecodecamp.org › news › slicing-and-indexing-in-python
Slicing and Indexing in Python – Explained with Examples
December 11, 2025 - In these examples, we have used slicing to extract a range of characters from the sentence string. The 4:9 slice means that we are selecting characters starting from index 4 (inclusive) up to index 9 (exclusive), which correspond to the second word "quick".
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.

🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
Why and how are selecting python list indexes inclusive and exclusive? - Python FAQ - Codecademy Forums
June 30, 2019 - Answer When selecting from a list in python, you may have noticed the saying ‘inclusive’ or ‘exclusive’, this is usually referring to the slice notation mylist[start:stop] where the start index is inclusive but the stop index is exclusive.
🌐
Python.org
discuss.python.org › python help
Advanced slicing rules? - Python Help - Discussions on Python.org
August 14, 2022 - So I’m taking a quiz and the first question asks something that was never written or spoken once in the section on lists as they pertain to slicing… which is absolutely infuriating as I am someone who tries to understand EVERYTHING before moving on: Question 1: What are the values of list_b and list_c after the following snippet? list_a = [1, 2, 3] list_b = list_a[-2:-1] list_c = list_a[-1:-2] To me this answer would be: list_b = [2,3] list_c = [3,2] … but that is not one of the answer...
🌐
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 - By Dillion Megida Slicing an array is the concept of cutting out – or slicing out – a part of the array. How do you do this in Python? I'll show you how in this article. If you like watching video content to supplement your reading, here's a video ve...
🌐
O'Reilly
oreilly.com › library › view › pandas-for-everyone › 9780134547046 › app12.xhtml
L. Slicing Values - Pandas for Everyone: Python Data Analysis, First Edition [Book]
December 15, 2017 - L. Slicing Values Python is a zero-indexed language (things start counting from zero), and is also left inclusive, right exclusive you are when specifying a range of values. This...
Author   Daniel Y. Chen
Published   2017
Pages   410
🌐
Wikipedia
en.wikipedia.org › wiki › Array_slicing
Array slicing - Wikipedia
3 weeks ago - With Python standard lists (which are dynamic arrays), every slice is a copy. Slices of NumPy arrays, by contrast, are views onto the same underlying buffer. ... Both bounds are inclusive and can be omitted, in which case they default to the declared array bounds.
🌐
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 ...
🌐
Programiz
programiz.com › python-programming › numpy › array-slicing
NumPy Array Slicing (With Examples)
... Array Slicing is the process of extracting a portion of an array. With slicing, we can easily access elements in the array. It can be done on one or more dimensions of a NumPy array. ... Note: When we slice arrays, the start index is inclusive but the stop index is exclusive.