It starts counting from "2" going backwards (step -1) until "-5" is reached - but reaching the element "-5" would require positive step in this case.

For example the output of:

i[2::-1]

is: [2, 1, 0]

Answer from Lemurata on Stack Overflow
Top answer
1 of 2
8

I was pointed to the reference implementation (hattip to the Anonymous Benefactor) and found that it is fairly straightforward to understand the behavior from there. To be complete, IMHO this behavior is unintuitive, but it nevertheless is well defined and matches the reference implementation.

Two CPython files are relevant, namely the ones describing list_subscript and PySlice_AdjustIndices. When retrieving a slice from a list as in this case, list_subscript is called. It calls PySlice_GetIndicesEx, which in turn calls PySlice_AdjustIndices. Now PySlice_AdjustIndices contains simple if/then statements, which adjust the indices. In the end it returns the length of the slice. To our case, the lines

if (*stop < 0) {
    *stop += length;
    if (*stop < 0) {
        *stop = (step < 0) ? -1 : 0;
    }
}

are of particular relevance. After the adjustment, x[0:-len(x)-1:-1] becomes x[0:-1:-1] and the length 1 is returned. However, when x[0:-1:-1] is passed to adjust, it becomes x[0:len(x)-1:-1] of length 0. In other words, f(x) != f(f(x)) in this case.

It is amusing to note that there is the following comment in PySlice_AdjustIndices:

/* this is harder to get right than you might think */

Finally, note that the handing of the situation in question is not described in the python docs.

2 of 2
6

The fact that

> x[-1:-4:-1] 
[6, 5, 4]
> x[0:-4:-1] 
[]

should not surprise you! It is fairly obvious that you can slice a list from the last to the fourth-last element in backwards steps, but not from the first element.

In

x[0:i:-1]

the i must be < -len(x) in order to resolve to an index < 0 for the result to contain an element. The syntax of slice is simple that way:

x[start:end:step]

means, the slice starts at start (here: 0) and ends before end (or the index referenced by any negative end). -len(x) resolves to 0, ergo a slice starting at 0 and ending at 0 is of length 0, contains no elements. -len(x)-1, however, will resolve to the actual -1, resulting in a slice of length 1 starting at 0.

Leaving end empty in a backward slice is more intuitively understood:

> l[2::-1]
[3, 2, 1]
> l[0::-1]
[1]
Discussions

Negative Slicing in Python
In this code, -1 index is 3, and -2 index is 2, right? But since we don’t include the second index itself, then we only have one value which is 3. However, why is the result an empty list? nums = [1,2,3] vals = nums [-1:-2] print (vals) Thank you in advance. More on discuss.python.org
🌐 discuss.python.org
3
0
September 8, 2023
Negative step indexing on List in Python - Stack Overflow
So, my confusion on slicing a list in reverse order took a hit when I tried to compare the two commands, one with their default values and the other one with the actual command PS: I'm trying to re... More on stackoverflow.com
🌐 stackoverflow.com
Why does Python refuse to slice a list with negative step?
nums[-1:1:-2] You're going backwards, so start at the end. Edit: nums[-2:0:-2] in your case. More on reddit.com
🌐 r/Python
10
0
September 23, 2025
List slicing with negative index
On negative step, the default start and stop are reversed. Start is len-1 stop is 0. More on reddit.com
🌐 r/learnpython
5
2
December 15, 2021
🌐
Knowledgehills
knowledgehills.com › python › negative-indexing-slicing-stepping-comparing-lists.htm
Python Lists – Negative Indexing, Slicing, Stepping, Comparing, Max and Min – Knowledge Hills
lst = ['Ajay', 'Bobby','Ashok', 'Vijay', 'Anil', 'Rahul','Alex', 'Christopher'] print (lst[1:]) print (lst[0:]) print (lst[2:-2]) # all elements starting from third element but skips the last two elements. print (lst[::2]) # this will print all alternate elements (begin to end in steps of 2) print (lst[::-1]) # this will print all elements in reverse order ... The first print command will skip the first element and print the entire list whereas the second print command to print lst1[0:] will print the entire list as it is. The third print combines slicing with a negative index.
🌐
Python.org
discuss.python.org › python help
Negative Slicing in Python - Python Help - Discussions on Python.org
September 8, 2023 - In this code, -1 index is 3, and -2 index is 2, right? But since we don’t include the second index itself, then we only have one value which is 3. However, why is the result an empty list? nums = [1,2,3] vals = nums [-1:-2] print (vals) Thank you in advance.
🌐
Python Morsels
pythonmorsels.com › slicing
Python list slicing (with examples) - Python Morsels
March 8, 2024 - The most common step value to see ... 'apple', 'watermelon'] Whenever a negative step value is given, the default meaning of start and stop changes....
🌐
Stack Overflow
stackoverflow.com › questions › 65215401 › negative-step-indexing-on-list-in-python
Negative step indexing on List in Python - Stack Overflow
But if we use negative slicing, we can use [-1:-5:-1]. This way, we go from right to left because of -1 step index, then we start with Papaya (-1) and to go to apple (-4), we need to to put a number beyond apple, and here we can put -5 as ending ...
Find elsewhere
🌐
Reddit
reddit.com › r/python › why does python refuse to slice a list with negative step?
Why does Python refuse to slice a list with negative step? : r/Python
September 23, 2025 - The slice components are start, stop, step, in that order. With a negative step, your start has to be a higher index than your stop for it to contain anything.
🌐
Reddit
reddit.com › r/learnpython › list slicing with negative index
r/learnpython on Reddit: List slicing with negative index
December 15, 2021 -

Although I know how slicing works but following examples kind of stumped me.

values = [3,4,3,7,8,9,5]
values[:3:-1]    #o/p [5,9,8]
values[5:3:-1]    #o/p [9,8]

I always thought in list[start:stop:step], 'start' defaults to 0, 'stop' defaults to length-1 and 'step' defaults to 1. But this doesn't make sense here. What are the rules? Link to official docs will also be appreciated as I couldn't find that.

🌐
Succeed Python
succeedpython.com › home › can you have negative step slices in python?
Can You Have Negative Step Slices in Python? - Succeed Python
January 6, 2025 - Using our previous list, if you’d ... step slicing works in more detail: If you set start greater than stop and specify a negative step, Python will return a slice of the list from the starting index moving back toward the stop index....
🌐
GeeksforGeeks
geeksforgeeks.org › python › slicing-with-negative-numbers-in-python
Slicing with Negative Numbers in Python - GeeksforGeeks
July 16, 2026 - In this example, we extract alternate elements from the list in reverse order. By passing -2 as the step, we skip one element while moving backwards. Python · num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] alt = num[::-2] print(alt) alt2 = num[slice(None, ...
🌐
USAVPS
usavps.com › home › python › python tutorial: how to understand negative step in slicing in python?
Python Tutorial: How to Understand Negative Step in Slicing in Python? - USAVPS
November 8, 2024 - Reversing a Sequence: Easily reverse lists or strings without using additional functions. Extracting Subsets: Retrieve specific elements from a sequence in reverse order. Data Manipulation: Useful in data analysis tasks where order matters. Understanding negative steps in slicing is a valuable skill for any Python programmer.
🌐
GitHub
github.com › modular › modular › discussions › 2234
Fix List slicing and String slicing to match Python when step is negative · modular/modular · Discussion #2234
April 7, 2024 - By preserving the programmers intent to include the end of the range it can correctly handle both unspecified start or end as well as negative start or end. Whichever direction you are slicing in the start index is inclusive while the end index is exclusive. So with step = -1, end = -1 if given by the programmer meanssize - 1 but if the programmer has specified end = None then Slice.end needs to be -1 so that the 0 index value is included in the slice.
Author: modular
🌐
Python Examples
pythonexamples.org › python-range-with-negative-step
Python Range with Negative Step Value
Range with negative step creates a sequence of integers that start at a higher value and stop at a lower value.
🌐
datarekha
datarekha.com › interview › python › how does python list slicing work, including step and negative indices?
How does Python list slicing work, including step and negative indices? — Python interview question & answer — datarekha
June 29, 2026 - Slicing uses the syntax `seq[start:stop:step]` and returns a new list containing elements from index `start` up to but not including `stop`, stepping by `step`. Negative indices count from the end; a negative step reverses direction.
🌐
Learn By Example
learnbyexample.org › python-list-slicing
Python List Slicing - Learn By Example
June 20, 2024 - When using a negative step, ensure the start index is greater than the stop index. When you omit the start index, the slice begins at the start of the list.
🌐
Real Python
realpython.com › lessons › range-decrementing
Decrementing With range() (Video) – Real Python
If you do that, you need to make ... rather -4 because you don’t include -6. 00:00 We can supply a negative step value to generate a list of numbers that is decreasing....
Published: October 15, 2019
🌐
TutorialsPoint
tutorialspoint.com › what-is-a-negative-indexing-in-python
What is a Negative Indexing in Python?
August 25, 2023 - List: [10, 20, 30, 40, 50] Last element: 50 Last 3 elements: [30, 40, 50] Reversed list: [50, 40, 30, 20, 10] Negative indexing in Python provides an intuitive way to access elements from the end of sequences.
🌐
Python Examples
pythonexamples.org › python-range
range() Built-in Function -
Usually, when step is negative, start is greater than the stop, and r[i] should be greater than stop.