Yes, calling s[0:-1] is exactly the same as calling s[:-1].

Using a negative number as an index in python returns the nth element from the right-hand side of the list (as opposed to the usual left-hand side).

so if you have a list as so:

myList = ['a', 'b', 'c', 'd', 'e']
print myList[-1] # prints 'e'

the print statement will print "e".

Once you understand that (which you may already, it's not entirely clear if that's one of the things you're confused about or not) we can start talking about slicing.

I'm going to assume you understand the basics of a slice along the lines of myList[2:4] (which will return ['c', 'd']) and jump straight into the slicing notation where one side is left blank.

As you suspected in your post, myList[:index] is exactly the same as myList[0:index].

This is also works the other way around, by the way... myList[index:] is the same as myList[index:len(myList)] and will return a list of all the elements from the list starting at index and going till the end (e.g. print myList[2:] will print ['c', 'd', 'e']).

As a third note, you can even do print myList[:] where no index is indicated, which will basically return a copy of the entire list (equivalent to myList[0:len(myList)], returns ['a', 'b', 'c', 'd', 'e']). This might be useful if you think myList is going to change at some point but you want to keep a copy of it in its current state.

If you're not already doing it I find just messing around in a Python interpreter a whole bunch a big help towards understanding these things. I recommend IPython.

Answer from Redwood on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › slicing-with-negative-numbers-in-python
Slicing with Negative Numbers in Python - GeeksforGeeks
July 16, 2026 - ... text = "DataScience" left = ... a list called items. Using negative slicing, we extract last four elements as vegetables and two elements before them as fruits....
Top answer
1 of 9
47

Yes, calling s[0:-1] is exactly the same as calling s[:-1].

Using a negative number as an index in python returns the nth element from the right-hand side of the list (as opposed to the usual left-hand side).

so if you have a list as so:

myList = ['a', 'b', 'c', 'd', 'e']
print myList[-1] # prints 'e'

the print statement will print "e".

Once you understand that (which you may already, it's not entirely clear if that's one of the things you're confused about or not) we can start talking about slicing.

I'm going to assume you understand the basics of a slice along the lines of myList[2:4] (which will return ['c', 'd']) and jump straight into the slicing notation where one side is left blank.

As you suspected in your post, myList[:index] is exactly the same as myList[0:index].

This is also works the other way around, by the way... myList[index:] is the same as myList[index:len(myList)] and will return a list of all the elements from the list starting at index and going till the end (e.g. print myList[2:] will print ['c', 'd', 'e']).

As a third note, you can even do print myList[:] where no index is indicated, which will basically return a copy of the entire list (equivalent to myList[0:len(myList)], returns ['a', 'b', 'c', 'd', 'e']). This might be useful if you think myList is going to change at some point but you want to keep a copy of it in its current state.

If you're not already doing it I find just messing around in a Python interpreter a whole bunch a big help towards understanding these things. I recommend IPython.

2 of 9
19
>>> l = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz&']

# I want a string up to 'def' from 'vwx', all in between
# from 'vwx' so -2;to 'def' just before 'abc' so -9; backwards all so -1.
>>> l[-2:-9:-1]
['vwx', 'stu', 'pqr', 'mno', 'jkl', 'ghi', 'def']

# For the same 'vwx' 7 to 'def' just before 'abc' 0, backwards all -1
>>> l[7:0:-1]
['vwx', 'stu', 'pqr', 'mno', 'jkl', 'ghi', 'def']

Please do not become listless about list.

  1. Write the first element first. You can use positive or negative index for that. I am lazy so I use positive, one stroke less (below 7, or -3 for the start).
  2. Index of the element just before where you want to stop. Again, you can use positive or negative index for that (below 2 or -8 for stop).
  3. Here sign matters; of course - for backwards; value of stride you know. Stride is a 'vector' with both magnitude and direction (below -1, backwards all).

    l = [0,1,2,3,4,5,6,7,8,9]
    l[7:2:-1], l[-3:2:-1], [-3:-8:-1],l[7:-8:-1]
    

    All result in [7, 6, 5, 4, 3].

Discussions

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
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
python - What is the use case for negative slicing and indexing in lists? - Stack Overflow
Referring to 30 Python Language features 1.6 List slices with negative indexing: >>> a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> a[-4:-2] [7, 8] Where is negative slicing and More on stackoverflow.com
🌐 stackoverflow.com
list - Negative Indexing & Slicing Python - Stack Overflow
Long time reader first time poster, ever. I am trying to understand all I can about indexing, slicing, negative indexing, etc. with lists. If I have a list: toeFriendly_terms=['feet', 'shoes', ' More on stackoverflow.com
🌐 stackoverflow.com
🌐
LabEx
labex.io › tutorials › python-how-to-slice-lists-with-negative-indices-435398
How to slice lists with negative indices | LabEx
In Python, list slicing follows the syntax: list[start:end:step] graph LR A[Start Index] --> B[End Index] B --> C[Step Value] ## Sample list numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ## Basic slicing print(numbers[2:7]) ## [2, 3, 4, 5, 6] ...
🌐
Knowledgehills
knowledgehills.com › python › negative-indexing-slicing-stepping-comparing-lists.htm
Python Lists – Negative Indexing, Slicing, Stepping, Comparing, Max and Min – Knowledge Hills
The fifth print combines slicing with a negative step. The output of this third print statement will print all elements starting from ending element to the beginning element. Basically the reverse of the list. This stackoverflow discussion is very useful if you like to understand more about slicing. Also this python doc has the official definition.
🌐
EyeHunts
tutorial.eyehunts.com › home › negative slicing in python | example code
Negative slicing in Python | Example code - EyeHunts
October 21, 2021 - ... Calling s[0:-1] is exactly the same as calling s[:-1]. myList = ['A', 'B', 'C', 'D', 'E'] print(myList[-1]) ... Do comment if you have any doubts and suggestions on this Python slice topic.
🌐
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.

🌐
PREP INSTA
prepinsta.com › home › python tutorial › slicing with negative numbers in python
Slicing with Negative Numbers in Python | PrepInsta
September 9, 2023 - ... #Initialize the String String = 'PrepInsta' #Slicing using 1 negative index arr = String[-2:] print(arr) #Slicing using 1 negative index arr = String[:-3] print(arr) #Slicing using 3rd negative index arr = String[::-1] print(arr) #Slicing ...
Find elsewhere
🌐
EITCA
eitca.org › home › how do negative indexes work in python when accessing elements in a list?
How do negative indexes work in Python when accessing elements in a list? - EITCA Academy
August 3, 2023 - Slicing with negative indexes works ... we can use the slice -3: (which is equivalent to [3, 4, 5]): python numbers = [1, 2, 3, 4, 5] last_three_elements = numbers[-3:] print(last_three_elements) # Output: [3, 4, 5]...
🌐
TutorialsPoint
tutorialspoint.com › what-is-a-negative-indexing-in-python
What is a Negative Indexing in Python?
August 25, 2023 - Negative indexing in Python allows you to access elements from the end of a sequence (string, list, tuple) by using negative numbers. Instead of counting from the beginning (0, 1, 2...), negative indexing counts backwards from the last element (-1, -2, -3...). ...
🌐
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…
🌐
LabEx
labex.io › tutorials › python-how-to-slice-sequences-with-negative-index-431287
How to slice sequences with negative index | LabEx
In LabEx's advanced Python courses, ... None ## Robust slicing implementation sample_list = [1, 2, 3, 4, 5] result = safe_slice(sample_list, start=1, end=-1, step=2) print(result) ## Output: [2, 4] By mastering negative index ...
🌐
TutorialKart
tutorialkart.com › python › how-to-slice-a-list-with-negative-indices-in-python
How to Slice a List with Negative Indices in Python
February 10, 2025 - -1 corresponds to the last element, but since slicing excludes the stop index, it stops at “f”. ... A negative step value allows slicing the list in reverse order. ... # Original list words = ["Python", "Java", "C++", "JavaScript", "Ruby"] ...
🌐
W3Schools
w3schools.com › python › gloss_python_string_negative_indexing.asp
Python String Negative Indexing
Remove List Duplicates Reverse ... from the end of the string: Get the characters from position 5 to position 1, starting the count from the end of the string: b = "Hello, World!" print(b[-5:-2]) Try it Yourself » ...
🌐
DEV Community
dev.to › hichem-mg › negative-indexing-in-python-with-examples-1ind
Negative Indexing in Python, with Examples 🐍 - DEV Community
June 9, 2024 - When slicing with a step, be careful with negative indices to avoid confusion and ensure the slice direction is correct. numbers = [10, 20, 30, 40, 50] # This will return an empty list because the start is after the stop print(numbers[-1:-3:-1]) ...
🌐
Medium
medium.com › @tabusheikh278 › mastering-series-indexing-in-python-a-deep-dive-into-integer-negative-slicing-negative-532a7e123fac
“Mastering Series Indexing in Python: A Deep Dive into Integer, Negative, Slicing, Negative Slicing, and Fancy Indexing” | by Thabasum Shaikh | Medium
January 5, 2024 - In this example, the negative slice includes elements at indices -3 and -2, up to, but not including, index -1, effectively extracting the sub-sequence [3, 4] from the end of the list.
🌐
Stack Overflow
stackoverflow.com › questions › 59304244 › negative-indexing-slicing-python
list - Negative Indexing & Slicing Python - Stack Overflow
So there are three ways to do this it seems: 1. .reverse() - mutates the original list 2. some_list[::-1] - 'Further, to print whole List in reverse order, use [::-1].' [link]geeksforgeeks.org/python-list 3. reversed() - I can't anything really explaining this. Maybe the documentation. I'll go check that. Thanks again Don. 2019-12-12T12:46:36.63Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with these tags.
🌐
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.
🌐
AlgoCademy
algocademy.com › link
Negative Index in Python | AlgoCademy
Unlike other languages, Python does not throw an error when we try to access list elements with negative indexes. For example, we can use the index -1 to select the last element of a list, even when we don’t know how many elements are in a list:
🌐
Sentry
sentry.io › sentry answers › python › python slice notation
Python slice notation | Sentry
October 21, 2022 - In the example below, a string is sliced starting at index 2, stopping when the array is complete, and taking the values at every second step. num_string = "0123456" even_nums = num_string[2::2] print(even_nums) ... Slicing can use negative indexing.