The syntax is:

Use with AIa[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:

Use with AIa[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:

Use with AIa[-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:

Use with AIa[::-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.:

Use with AIa[start:stop:step]

is equivalent to:

Use with AIa[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 › python_strings_slicing.asp
Python - Slicing Strings
You can return a range of characters by using the slice syntax.
🌐
GeeksforGeeks
geeksforgeeks.org › python › string-slicing-in-python
String Slicing in Python - GeeksforGeeks
Explanation: The slice s[::-1] starts from the end and steps backward through the string, which effectively reversing it. This method does not alter the original string. Let’s see how to use string slicing in Python with the examples below:
Published: October 7, 2026
🌐
TechVidvan
techvidvan.com › tutorials › python-slicing
Slicing in Python with Python Slice Function and Indexing - TechVidvan
April 11, 2020 - The slice function takes in the values of start, stop and step as arguments and returns a slice object. This slice object can then be passed within the square brackets in place of start:stop:step to access the desired slice.
🌐
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'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.
🌐
Python
docs.python.org › 3 › c-api › slice.html
Slice Objects — Python 3.15.2 documentation
The type object for slice objects. This is the same as slice in the Python layer.
🌐
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]
Find elsewhere
🌐
Real Python
realpython.com › ref › glossary › slice
slice | Python Glossary – Real Python
In Python, a slice is an object that allows you to extract a portion of a sequence, such as a list, tuple, or string.
🌐
YouTube
youtube.com › fabio musanni - programming channel
Python Slicing String and List | Python Slice Notation Explained - YouTube
💻 *Get my Source Codes and support the channel* ❤️: https://www.buymeacoffee.com/fabiomusanni/extras⬇️ *LEARN ON THE BEST LEARNING PLATFORMS (LINKS BELOW)* ...
Published: November 16, 2022
Views: 899
🌐
W3Schools
w3schools.com › python › gloss_python_string_slice.asp
Python Slice Strings
You can return a range of characters by using the slice syntax. Specify the start index and the end index, separated by a colon, to return a part of the string. Get the characters from position 2 to position 5 (not included): b = "Hello, World!" print(b[2:5]) Try it Yourself » · Python Strings Tutorial String Literals Assigning a String to a Variable Multiline Strings Strings are Arrays Negative Indexing on a String String Length Check In String Format String Escape Characters
Top answer
1 of 16
6670

The syntax is:

Use with AIa[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:

Use with AIa[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:

Use with AIa[-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:

Use with AIa[::-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.:

Use with AIa[start:stop:step]

is equivalent to:

Use with AIa[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:

Use with AI +---+---+---+---+---+---+
 | 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.

🌐
DEV Community
dev.to › thrivensunshine › slicing-in-python-2hlk
Slicing in Python - DEV Community
April 3, 2020 - One of these similarities include the idea of "slicing" some form of data. Slicing does exactly what it implies, it "slices" up data into smaller parts. Every language has their own particular way of doing this. Lets take a look at how Python in particular handles this kind of operation.
🌐
YouTube
youtube.com › programmingknowledge
Python Tutorial for Beginners 8 - Python Slices or Slicing - YouTube
In this video I am going to show How to use Slice function or slicing with Python Collections. Also I am going to show how to use Negative index with Python ...
Published: September 6, 2014
Views: 215K
🌐
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.
🌐
YouTube
youtube.com › watch
Python Tutorial: Slicing Lists and Strings - YouTube
In this video we will look at how to slice lists and strings in Python. Slicing allows us to extract certain elements from these lists and strings. This can ...
Published: October 29, 2015
🌐
The Python Coding Stack
thepythoncodingstack.com › notes from the near future › a slicing story
A Slicing Story - The Python Coding Stack
September 24, 2023 - 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.
🌐
Sentry
sentry.io › sentry answers › python › python slice notation
Python Slice Notation for Strings and Lists | Sentry
September 17, 2026 - Use Python slice notation to extract substrings and sublists with start, stop, and step indices, including negative indexing and reverse iteration
🌐
Sentry
sentry.io › sentry answers › python › slicing in python
Python: How Slice Notation Works | Sentry
September 24, 2026 - Python’s slice notation provides a quick way for programmers to extract sections of sequences, such as lists and strings.
🌐
Python Morsels
pythonmorsels.com › slicing
Python list slicing (with examples) - Python Morsels
August 3, 2026 - In Python, slicing uses colons in square brackets to grab part of a list, string, or tuple: first items, last items, reverse, and step.
🌐
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 ...
🌐
YouTube
youtube.com › watch
Python Slicing | Python Slicing Strings & Lists | Python Tutorial | Python Programming | Simplilearn - YouTube
"️️🔥Professional Certificate in AI and Machine Learning - https://www.simplilearn.com/professional-aiml-program?utm_campaign=1SDUW_-cPFw&utm_medium=Descript...
Published: January 7, 2019