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
🌐
W3Schools
w3schools.com › python › ref_func_slice.asp
Python slice() Function
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 Training ... Create a tuple and a slice object.
🌐
Runestone Academy
runestone.academy › ns › books › published › fopp › Sequences › TheSliceOperator.html
6.6. The Slice Operator — Foundations of Python Programming
The slice operator [n:m] returns the part of the string starting with the character at index n and go up to but not including the character at index m.
Discussions

A Comprehensive Guide to Slicing in Python
The start/end indexing when going in reverse has always taken a level of extra mental effort that I don't like. Like excluding the first and last item using [1:-1] is intuitive to me, but doing the same in reverse by doing [-2:0:-1] annoys me (though I do get why its like that). That is why I tend to do [1:-1][::-1] instead. More on reddit.com
🌐 r/Python
40
356
February 1, 2022
slice - How slicing in Python works - Stack Overflow
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. A slice object can represent a slicing operation... More on stackoverflow.com
🌐 stackoverflow.com
What does slice operation actually return in python - Stack Overflow
"All slice operations return a new list containing the requested elements" This is from the python tutorials. But if this is the case then why does this piece of code behave this way: >... More on stackoverflow.com
🌐 stackoverflow.com
Slice operator
The notation is list[start:stop:step], where start is inclusive and stop is exclusive. By doing list[0:2], you are effectively only indexing 0 and 1 since 2 is not included. When you do list[2:2], you will get an empty list back since 2 is not included since it is the stop value. More on reddit.com
🌐 r/learnpython
10
2
December 8, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-slice-function
Python slice() function - GeeksforGeeks
June 8, 2026 - Explanation: slice(-1, -5, -1) starts from the last element and moves backward with a step of -1. Comment · Python Fundamentals · Introduction1 min read · Input & Output2 min read · Variables4 min read · Operators4 min read · Keywords2 min read · Data Types4 min read ·
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › brackets › slicing.html
[] (slicing) — Python Reference (The Right Way) 0.1 documentation
>>> +---+---+---+---+ >>> |-4 |-3 |-2 |-1 | <= negative indexes >>> +---+---+---+---+ >>> | A | B | C | D | <= sequence elements >>> +---+---+---+---+ >>> | 0 | 1 | 2 | 3 | <= positive indexes >>> +---+---+---+---+ >>> |<- 0:3:1 ->| <= extent of the slice: "ABCD"[0:3:1] ... It can be read as: get every single one item between indexes 0 and 2 (exclusive). The next example shows usage of the step argument: ... That can be interpreted as: get every second element between indexes 0 and 4. Usage of start, stop and step operators is optional:
🌐
Reddit
reddit.com › r/python › a comprehensive guide to slicing in python
r/Python on Reddit: A Comprehensive Guide to Slicing in Python
February 1, 2022 - I've always found array slicing in python to be very powerful and useful, and a thing i wish more languages had. For my common use case (dealing with text) it's very fast to code something up. ... I'm very new to Python and one thing I find confusing and unintuitive is that some things, like slices, start counting at 0 but other things like groups in regular expressions start counting at 1.
🌐
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__() in The Manor House, the Oak-Panelled Library, the Vending Machine, and Python's `__getitem__()`. In this new class called TestList, which inherits from list, you first print the value and data type of the argument in the __getitem__() method, and then you call the list's __getitem__() method and return its value. This is what super().__getitem__(item) does since list is the superclass for TestList. The syntax 2:7 within the square brackets represents a slice object.
Find elsewhere
🌐
Codecademy
codecademy.com › docs › python › built-in functions › slice()
Python | Built-in Functions | slice() | Codecademy
September 26, 2025 - The slice() function creates a slice object that specifies how to slice sequences like strings, lists, tuples, and ranges. It provides a way to extract specific portions of sequences by defining the start, stop, and step parameters, offering ...
Top answer
1 of 16
6667

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
729

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.

🌐
Python Morsels
pythonmorsels.com › implementing-slicing
Implementing slicing - Python Morsels
March 27, 2023 - That way slicing ProxySequence ... >>> p = ProxySequence(string) >>> p[1:] ProxySequence('bcdefghi') Python's slicing syntax is powered by slice objects....
🌐
DataCamp
datacamp.com › tutorial › python-slice
Python Slice: Useful Methods for Everyday Coding | DataCamp
January 15, 2025 - Understanding whether Python creates a copy or a view is essential for memory management when slicing data structures, especially with large datasets. Know that with built-in lists and strings, Slicing always creates a copy of the original sequence, but with NumPy arrays, slicing creates a view, meaning both the original array and the slice point to the same data in memory. In the following code, our slicing operation creates a view of the original NumPy array rather than a copy.
Top answer
1 of 1
5

You are confusing expressions with assignment. Getting values (reading) is handled differently from setting values (writing).

Assignment (setting) re-uses syntax to specify a target. In an assignment like a[:] = ..., a[:] is a target to which the assignment takes place. Using a[:] in an expression produces a new list.

In other words: you have two different language statements, that are deliberately using the same syntax. They are still distinct however.

See the Assignment statements reference documentation:

assignment_stmt ::=  (target_list "=")+ (starred_expression | yield_expression)
target_list     ::=  target ("," target)* [","]
target          ::=  identifier
                     | "(" [target_list] ")"
                     | "[" [target_list] "]"
                     | attributeref
                     | subscription
                     | slicing
                     | "*" target

[...]

  • If the target is a slicing: The primary expression in the reference is evaluated. It should yield a mutable sequence object (such as a list). The assigned object should be a sequence object of the same type. Next, the lower and upper bound expressions are evaluated, insofar they are present; defaults are zero and the sequence’s length. The bounds should evaluate to integers. If either bound is negative, the sequence’s length is added to it. The resulting bounds are clipped to lie between zero and the sequence’s length, inclusive. Finally, the sequence object is asked to replace the slice with the items of the assigned sequence. The length of the slice may be different from the length of the assigned sequence, thus changing the length of the target sequence, if the target sequence allows it.

(Bold emphasis mine).

Compare this with the Slicings section in the expressions reference documentation; slicing in an expression produces a slice() object, which the list.__getitem__ method interprets as a request for a new list object with the matching indices copied over. Other object types can choose to interpret a slice object differently.

Note that there is a third operation, the del statement to delete references, including slices. Deletion takes the same target_list syntax and asks to remove the indices indicated by a slice.

These three operations are, under the hood, implemented by the object.__getitem__() (reading), object.__setitem__() (writing) and object.__delitem__() (deleting) hook methods; the key argument to each of these operations is a slice() object, but only __getitem__ is expected to return anything.

🌐
Python
docs.python.org › 3 › c-api › slice.html
Slice Objects — Python 3.14.7 documentation
Retrieve the start, stop and step indices from the slice object slice, assuming a sequence of length length.
🌐
Analytics Vidhya
analyticsvidhya.com › home › python slicing: 9 useful methods for everyday coding
Python Slicing: 9 Useful Methods for Everyday Coding
May 16, 2025 - One is [start: end: step] and the other is the .slice(start, stop, step) function. In this section, first we will go through the syntax of these slicing operations, after this we will explore the major types of slicing that we can perform in Python.
🌐
freeCodeCamp
freecodecamp.org › news › slicing-and-indexing-in-python
Slicing and Indexing in Python – Explained with Examples
December 11, 2025 - In Python, you perform slicing using the colon : operator. The syntax for slicing is as follows: ... where start_index is the index of the first element in the sub-sequence and end_index is the index of the last element in the sub-sequence ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-slicing
Python List Slicing - GeeksforGeeks
List slicing is a technique used to extract a portion of a list by specifying a range of indices. It returns a new list containing the selected elements while leaving the original list unchanged.
Published: July 16, 2026
🌐
Simplilearn
simplilearn.com › home › resources › software development › your ultimate python tutorial for beginners › everything you need to know about python slicing
Everything You Need to Know About Python Slicing
January 26, 2025 - Python is a widely used, general-purpose programming language. So what is slicing and negative indices? Learn all about Python slicing, index, & more. Read On!
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Luis Llamas
luisllamas.es › home › courses › python programming course
Python Slices for Cutting Sequences
November 20, 2024 - We can omit one, several, or even all parameters of the Slice. It will behave differently with each omission. ... first_except_three = numbers[3:] # Extracts elements from 3 to the end first_three = numbers[:3] # Extracts the first three elements ... Python allows the use of negative indices to refer to elements relative to the end of the sequence (instead of from the beginning).
🌐
Vultr Docs
docs.vultr.com › python › built-in › slice
Python slice() - Create Slice Object | Vultr Docs
November 21, 2024 - The slice() function in Python is a built-in method that enables you to create slice objects, which represent a set of indices specified by start, stop, and step parameters. Its main utility lies in extracting parts of sequences like strings, ...
🌐
DataFlair
data-flair.training › blogs › python-slice
Python Slice Constructor - Python Slice String & Slicing Tuple - DataFlair
April 25, 2026 - This aids readability and implements abstraction. To slice an iterable, we use the slicing operator, that is [ ]. To separate the start, stop, and step values, we use the colon ( : ).
🌐
Dot Net Perls
dotnetperls.com › slice-python
Python - Slice Examples - Dot Net Perls
A slice can be used to resize a list. We can remove elements past a certain length. This makes the list smaller (reduces its size). We can also pad a list with new elements. Tuples too may be sliced. Slicing notation is standardized throughout Python 3 objects.