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
🌐
Learn By Example
learnbyexample.org › python-list-slicing
Python List Slicing - Learn By Example
June 20, 2024 - In this example, we start at index 2, which corresponds to the letter ‘c’. Then we slice up to, but not including, index 7. This means we stop just before the letter ‘h’ at index 7. The result is a new list that contains the elements at indices 2 through 6, giving us the desired sequence of letters from ‘c’ to ‘g’. When slicing lists in Python, you can use negative indices as well.
🌐
Drbeane
drbeane.github.io › python › pages › collections › slicing.html
Slicing Lists — Python for Data Science
# Simple Slicing Example simpleList = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20] print(simpleList[3:7]) print(simpleList[5:]) print(simpleList[:8]) [6, 8, 10, 12] [10, 12, 14, 16, 18, 20] [0, 2, 4, 6, 8, 10, 12, 14] We can also use negative indices when specifying a slice of a list.
🌐
freeCodeCamp
freecodecamp.org › news › slicing-and-indexing-in-python
Slicing and Indexing in Python – Explained with Examples
December 11, 2025 - In this example, we have used slicing to insert a new list [40, 50] at index 4 in the numbers list. The 4:4 slice means that we are inserting the new list at index 4 (that is, before the element at index 4), but not deleting any existing elements.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-slicing
Python List Slicing - GeeksforGeeks
If we specify indices beyond the ... 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....
Published   July 23, 2025
🌐
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.
🌐
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 - Let’s look at this subject – feel free to follow along on your own editor or with an online Python compiler. ... >>> nums = [10, 20, 30, 40, 50, 60, 70, 80, 90] >>> some_nums = nums[2:7] >>> some_nums [30, 40, 50, 60, 70] So, here is our ...
Top answer
1 of 16
6656

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.

🌐
Programiz
programiz.com › python-programming › examples › list-slicing
Python Program to Slice Lists
In the above example, my_list[2:4] gives the elements between 2nd and the 4th positions. The starting position (i.e. 2) is included and the ending position (i.e. 4) is excluded. ... If you want to get elements at specified intervals, you can do it by using two :. In the above example, the items ...
🌐
Kansas State University
textbooks.cs.ksu.edu › intro-python › 07-lists › 05-slicing-lists
Slicing Lists :: Introduction to Python
June 27, 2024 - nums[:-2] - this creates a slice of the entire list except for the last two items. For example, we can start with a simple list, and then try the various list slicing methods to see what elements would be included in the new list. Here’s an example program that shows some of the various ways ...
Find elsewhere
🌐
W3Schools
w3schools.com › python › python_strings_slicing.asp
Python - Slicing Strings
Remove List Duplicates Reverse a String Add Two Numbers · 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 ...
🌐
Python Morsels
pythonmorsels.com › slicing
List slicing in Python - Python Morsels
March 8, 2024 - Let's say we have a fruits variable that points to a list: >>> fruits = ['watermelon', 'apple', 'lime', 'kiwi', 'pear', 'lemon', 'orange'] >>> fruits ['watermelon', 'apple', 'lime', 'kiwi', 'pear', 'lemon', 'orange'] ... If we put a colon and ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python list slice with examples
Python List Slice with Examples - Spark By {Examples}
May 31, 2024 - Negative indexes refer to the position of the elements from the end of the list. For example, you used the slice operator [-4:] to extract a subset of the list containing elements from the fourth-to-last element up to the end of the list.
🌐
Analytics Vidhya
analyticsvidhya.com › home › all about python list slicing with examples
All About Python List Slicing With Examples
May 20, 2025 - For example: text = "Hello, World!" substring = text[7:12] print(substring) # Output: "World" Similarly, tuples can also be sliced using list slicing syntax. We can extract sub-tuples from a tuple based on the specified indices.
🌐
Unstop
unstop.com › home › blog › python list slice | syntax, parameters & uses (+code examples)
Python List Slice | Syntax, Parameters & Uses (+Code Examples)
December 30, 2024 - First Empty Slice [3:2]: The slice [3:2] specifies a start index of 3 and a stop index of 2, which does not make sense because the start index is greater than the stop index. As a result, Python returns an empty list [].
🌐
Educative
educative.io › home › courses › python › list slicing
List Slicing - Python
Python 3.10.4 · my_list = [1, 5, 10, 15, 20, 25, 30] slice_list_from_start = my_list[:4] print(slice_list_from_start) Run · The above code will result in a list including elements from the start of the list up to the 4th index ([1,5,10,15]). Note how 20 (the 4th index) is not included in the list.
🌐
W3Schools
w3schools.com › python › ref_func_slice.asp
Python slice() Function
Remove List Duplicates Reverse a String Add Two Numbers · 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 ... Create a tuple and a slice object.
🌐
Python Tutorial
pythontutorial.net › home › python basics › python list slice
Python List Slice
March 26, 2025 - The following example uses the step to return a sublist that includes every 2nd element of the colors list: colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'] sub_colors = colors[::2] print(sub_colors) Code language: Python (python) ... When you use a negative step, the slice includes the list of elements starting from the last element to the first element.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › list slicing in python
List Slicing in Python
October 26, 2025 - Lst[-5:-2] slices from the 5th last element to the 2nd last. ... Lst[::-1] gives you a reversed list. ... If slicing is incompatible, you get an empty list: Lst[5:2]. In Python, think of indexing in lists, like giving a unique number to each item.
🌐
Board Infinity
boardinfinity.com › blog › list-slicing-in-python
List Slicing in Python | Board Infinity
August 13, 2025 - Explore list slicing in Python, including syntax, examples, and tips to efficiently access and manipulate specific portions of lists in your code
🌐
Studytonight
studytonight.com › post › list-slicing-in-python-with-examples
Python List Slicing
May 18, 2023 - my_first_list = [1,2,3, 'StudyTonight', 1.23] # slicing list and overiding its original value my_first_list = my_first_list[-1] print(my_first_list) my_list = [1,2,3, 'StudyTonight', 1.23] # slicing list and storing the new sliced list in different ...