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 โ€บ python_strings_slicing.asp
Python - Slicing Strings
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 ... You can return a range of characters by using the ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_slice.asp
Python slice() Function
Use the slice object to get only ... it Yourself ยป ยท The slice() function returns a slice object. A slice object is used to specify how to slice a sequence....
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
Is string slicing actually useful in real world applications?
If you are doing lot of text processing, then yes. Here's an example from my usecase. I have markdown files with code snippets starting with $ or >>> etc. I have to post process those files to extract only the command that comes after the prompt. Easiest solution is string slicing, since the length of the prompt is fixed. Also, slicing in Python can be applied to lists, tuples, strings, etc. So, even if you are not doing text processing, you can apply the knowledge elsewhere. More on reddit.com
๐ŸŒ r/learnpython
8
1
October 13, 2020
People also ask

How does slicing differ from indexing in Python
divstrongSlicing in Pythonstrong extracts a range of elements from a sequence creating a new subset while indexing retrieves a single element from a specific position in the sequence Slicing uses a start and end index whereas indexing uses just onenbspdiv
๐ŸŒ
scholarhat.com
scholarhat.com โ€บ home
What is Slicing in Python?
Can I reverse a list or string using slicing
divstrongYesstrong you can reverse a list or string using slicing by setting the step parameter to strong1strongdiv
๐ŸŒ
scholarhat.com
scholarhat.com โ€บ home
What is Slicing in Python?
Can I use negative indices in slicing
divstrongYesstrong negative indices can be used in slicing to access elements from the end of the sequencenbspdiv
๐ŸŒ
scholarhat.com
scholarhat.com โ€บ home
What is Slicing in Python?
Top answer
1 of 16
6666

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.

๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-slice
Python Slice: Useful Methods for Everyday Coding | DataCamp
January 15, 2025 - As I said, slicing is a core feature in Python, allowing developers to extract portions of sequences like lists, strings, and tuples. Python offers two primary ways to slice sequences without importing anything: the slicing : syntax and the slice() function.
๐ŸŒ
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.
๐ŸŒ
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
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ string-slicing-in-python
String Slicing in Python - GeeksforGeeks
String slicing in Python is a way to get specific parts of a string by using start, end and step values. Itโ€™s especially useful for text manipulation and data parsing. ... Explanation: In this example, we used the slice s[0:5] to obtain the ...
Published: July 12, 2025
๐ŸŒ
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 - 356 votes, 40 comments. Python Slicing is a powerful tool to access sequences. To learn more about the inner mechanics of slices, read this post ;)
๐ŸŒ
ScholarHat
scholarhat.com โ€บ home
What is Slicing in Python?
September 11, 2025 - Slicing in Python is a method used to extract specific sections of sequences like strings, lists, or tuples. By specifying a range of indices, you may quickly retrieve sub-sections of this sequence.
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ what-slicing-python-constantinos-pigiotis
What is slicing in Python?
April 2, 2023 - In #python, slicing is an operation of slicing a list. This means that it can extract some elements from a list using some preferred indexes.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-slice-function
Python slice() function - GeeksforGeeks
June 8, 2026 - slice() function is used to create a slice object that specifies how to extract a portion of a sequence such as a string, list or tuple. It allows selecting elements using start, stop and step values.
๐ŸŒ
Python Tutorial
pythontutorial.net โ€บ home โ€บ advanced python โ€บ python slicing in depth
Python Slicing in Depth
March 27, 2025 - For example: ... The slicing seq[start:stop] returns the elements starting at the index start up to the index stop - 1. Therefore, itโ€™s easier to visualize that the indexes are between the elements when you slice the sequence: Everything in ...
๐ŸŒ
Real Python
realpython.com โ€บ ref โ€บ glossary โ€บ slicing
slicing | Python Glossary โ€“ Real Python
In this syntax, start is the index where the slice begins, stop is the index where the slice ends (exclusive), and step determines the stride between each element in the slice. If you omit start, stop, or step, then they default to the beginning of the sequence, the end of the sequence, and a step of one, respectively. With slicing, you can quickly obtain a subset of items without modifying the original sequence, making it an essential feature for any Python programmer. Hereโ€™s a quick example of how you can use slicing with a list:
๐ŸŒ
The Python Coding Stack
thepythoncodingstack.com โ€บ the python coding stack โ€บ a slicing story
A Slicing Story - by Stephen Gruppetta
June 25, 2024 - The first item in nested_numbers hasn't changed and is the same inner list as before, [0, 1, 2]. However, the first item in subset_of_nested_lists is now the new list [999, 999, 999]. You can read more about shallow and deep copies in an article I wrote in the pre-Substack era: Shallow and Deep Copy in Python and How to Use __copy__(). So, slicing creates a copy of the subset of the sequence, right? Not so fastโ€ฆ ยท I have used lists in all the examples in this article so far. You can slice other sequences, too:
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ article โ€บ what-is-slicing-in-python-with-example
What is Slicing in Python with Example
May 13, 2024 - # slicing a string s = "Hello, ... # output: (3, 4) If you are In the above example, we create a string, list or tuple and then slice it using the slice operator....
๐ŸŒ
Medium
medium.com โ€บ @timothyjosephcw โ€บ what-is-python-slicing-and-how-does-slicing-in-python-work-2788632c5ba0
What is Python Slicing and How Does Slicing in Python Work? | by timothy joseph | Medium
August 22, 2024 - What is Python Slicing and How Does Slicing in Python Work? Python slicing, a versatile and creative technique, allows you to extract specific portions of sequences like lists, tuples, and strings โ€ฆ
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ python slicing: 9 useful methods for everyday coding
Python Slicing: 9 Useful Methods for Everyday Coding
May 16, 2025 - Byte sequence comes into the picture when we are using the binary data types, and slicing allows you to extract relevant parts of binary data with ease and efficiency. ... byte_seq = b'Hello, world!'
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ slicing
Python list slicing (with examples) - Python Morsels
March 8, 2024 - In Python, slicing uses colons in square brackets to grab part of a list, string, or tuple: first items, last items, reverse, and step.
๐ŸŒ
Duomly
blog.duomly.com โ€บ home โ€บ slicing in python what is it
Slicing in Python โ€“ what is it?
September 19, 2019 - Slicing in Python is a feature that enables accessing parts of sequences like strings, tuples, and lists. You can also use them to modify or delete the items of mutable sequences such as lists.
๐ŸŒ
YouTube
youtube.com โ€บ corey schafer
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
Views: 205K