If you're using a variable as the range endpoint, you can use None.

 start = 4
 end = None
 test[start:end]
Answer from recursive on Stack Overflow
๐ŸŒ
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 ...
Published ย  July 23, 2025
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ slicing
List slicing in Python - Python Morsels
March 8, 2024 - What do you think we might get ... 'pear', 'lemon', 'orange'] With Python's slicing syntax, the first item is the start index, and the second item is the stop index....
Discussions

I am confused about Slicing a List.
No. players[0:3] means "start at index 0, go until index 3-1", so that's the first 3 elements of your list. If you want the last 3 you need to use negative indexes. print(players[-3:]) More on reddit.com
๐ŸŒ r/learnpython
17
1
February 11, 2025
Slicing a list using a variable, in Python - Stack Overflow
Given a list a = range(10) You can slice it using statements such as a[1] a[2:4] However, I want to do this based on a variable set elsewhere in the code. I can easily do this for the first one ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
slice - How slicing in Python works - Stack Overflow
You made a cut before the element with index 2 and another cut before the element with index 5. So the result will be a slice between those two cuts, a list ['T', 'H', 'O']. ... Most of the previous answers clears up questions about slice notation. The extended indexing syntax used for slicing ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Slicing a list starting from given index and jumping/stepping it with some integer - Stack Overflow
I have the general idea of how to do this in php, but I am new to Python and not sure how to do it. I am trying to implement a function that returns a list containing every second element of every... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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 Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... You can return a range of characters by using the slice syntax...
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
The Python Coding Stack
thepythoncodingstack.com โ€บ the python coding stack โ€บ a slicing story
A Slicing Story - by Stephen Gruppetta
June 25, 2024 - You can read more about __getitem__() ... does since list is the superclass for TestList. The syntax 2:7 within the square brackets represents a slice object....
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ slicing-and-indexing-in-python
Slicing and Indexing in Python โ€“ Explained with Examples
December 11, 2025 - The syntax for slicing is as follows: ... at the end_index). To slice a sequence, you can use square brackets [] with the start and end indices separated by a colon....
๐ŸŒ
Learn By Example
learnbyexample.org โ€บ python-list-slicing
Python List Slicing - Learn By Example
June 20, 2024 - This syntax involves specifying the starting index (where your slice begins), the stopping index (where it ends), and the step size (how many elements you skip between each included element).
๐ŸŒ
Kansas State University
textbooks.cs.ksu.edu โ€บ intro-python โ€บ 07-lists โ€บ 05-slicing-lists
Slicing Lists :: Introduction to Python
June 27, 2024 - The method for creating list slices is very similar to how the range() function is used in Python. In effect, if the same values are provided as arguments to the range() function, then it will produce the list of indexes that will be used to generate the list slice. Beyond the simple syntax, ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ examples โ€บ list-slicing
Python Program to Slice Lists
To understand this example, you should have the knowledge of the following Python programming topics: ... The format for list slicing is list_name[start: stop: step].
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ what is list slicing in python?
What is List Slicing in Python? - Scaler Topics
May 4, 2023 - List slicing in python is done by the simple slicing operator i.e. colon(:). With the use of the operator one can specify where to start the slicing, where to end, and specify the step too.
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ all about python list slicing with examples
All About Python List Slicing With Examples
May 20, 2025 - In addition to the basic list slicing syntax, Python provides extended slices that allow us to skip elements while extracting a subsequence. We can select elements regularly by specifying a step value greater than 1.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python list slice with examples
Python List Slice with Examples - Spark By {Examples}
May 31, 2024 - How to slice a list into multiple lists in Python? You can easily slice a list in Python either by using the slice() function or slice notation. These
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.6 documentation
Return zero-based index of the first occurrence of value in the list. Raises a ValueError if there is no such item. The optional arguments start and end are interpreted as in the slice notation and are used to limit the search to a particular ...
Top answer
1 of 16
6664

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.