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
🌐
DataCamp
datacamp.com › tutorial › python-slice
Python Slice: Useful Methods for Everyday Coding | DataCamp
January 15, 2025 - Slicing can refer to using the built-in slice() function or the even more common bracket notation that looks like this: [start:end:step]. The functionality is a core part of the Python language, so you can perform slicing with or without importing any additional packages.
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.

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
List slicing with negative index
See this stackoverflow thread: Understanding slice notation More on reddit.com
🌐 r/learnpython
5
2
December 15, 2021
Help with Tkinter and string slicing please.

You can use the get method of stringvar to get the string you want. For example: print(year.get()) prints the year in the stringvariable.

More on reddit.com
🌐 r/learnpython
8
3
October 4, 2015
Why does Python reverse a list with [::-1]? Can someone explain this slicing logic?
To give us the best chance to help you, please include any relevant code. Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide ). If you have formatting issues or want to post longer sections of code, please use Privatebin , GitHub or Compiler Explorer . I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/pythonhelp
20
8
November 30, 2025
🌐
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 Bootcamp Python Training ... You can return a range of characters by using the slice syntax.
🌐
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 Bootcamp Python Training ... Create a tuple and a slice object.
🌐
GeeksforGeeks
geeksforgeeks.org › python › string-slicing-in-python
String Slicing in Python - GeeksforGeeks
Negative indexing makes it easy to get items without needing to know the exact length of the string. ... s[-4:] slices the string starting from the 4th character from the end ('m') to the end of the string.
Published   July 12, 2025
🌐
freeCodeCamp
freecodecamp.org › news › slicing-and-indexing-in-python
Slicing and Indexing in Python – Explained with Examples
December 11, 2025 - We could also extract all the even numbers from the list using slicing as follows: even_numbers = numbers[1::2] print(even_numbers) # output: [2, 4, 6, 8] In this example, we have used slicing to extract every other element starting from the ...
🌐
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:
Find elsewhere
🌐
DEV Community
dev.to › thrivensunshine › slicing-in-python-2hlk
Slicing in Python - DEV Community
April 3, 2020 - If you were to add a number after ... 'B1', 'C2']" for my list_splice we are essentially saying start at the 0 index, then move 3 spaces forward and stop. we have just successfully sliced our data But we aren't done ...
🌐
Programiz
programiz.com › python-programming › methods › built-in › slice
Python slice()
slice_object = slice(1, 5, 2) print(py_tuple[slice_object]) # ('y', 'h') ... py_list = ['P', 'y', 't', 'h', 'o', 'n'] py_tuple = ('P', 'y', 't', 'h', 'o', 'n') # contains indices -1, -2 and -3
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › brackets › slicing.html
[] (slicing) — Python Reference (The Right Way) 0.1 documentation
>>> +---+---+---+---+ >>> |-4 |-3 ... >>> +---+---+---+---+ >>> |<- 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:...
🌐
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....
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-slice-string
Python slice string | DigitalOcean
August 3, 2022 - Output: dlroWolleH Let’s look at some other examples of using steps and negative index values. ... Output: loo Here the substring contains characters from indexes 2,4 and 6. ... Output: lroWoll Here the index values are taken from end to start. The substring is made from indexes 1 to 7 from end to start. ... Output: lool Python slice works with negative indexes too, in that case, the start_pos is excluded and end_pos is included in the substring.
🌐
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.
🌐
DataFlair
data-flair.training › blogs › python-slice
Python Slice Constructor - Python Slice String & Slicing Tuple - DataFlair
April 25, 2026 - We can slice a string in Python using the Python slice() method. We can also specify the interval. Slicing a string may give us a substring when the step size is 1. ... Like in the previous example, we use positive indices here.
🌐
Python Tutorial
pythontutorial.net › home › advanced python › python slicing in depth
Python Slicing in Depth
March 27, 2025 - 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:
🌐
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
🌐
Medium
medium.com › @hariprakashh174 › mastering-slicing-in-python-a-beginners-guide-b87e742f57ff
Mastering Slicing in Python: A Beginner’s Guide | by HARIPRAKASH K | Medium
August 21, 2025 - # A sequence (list of numbers) numbers = [10, 20, 30, 40, 50, 60] # Slice from index 1 to 4 (stop is exclusive) result = numbers[1:4] print(result) #output [20, 30, 40] 👉 Here, start = 1 (20) and stop = 4 (excludes index 4 → 50).
🌐
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!' # Slice from index 0 to index 5 (exclusive) ...
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-slice-function
Python slice() function - GeeksforGeeks
June 8, 2026 - Example 1: In this example, a string is sliced using different slice() objects to extract selected characters. ... Explanation: slice(5) extracts characters from index 0 to 4, while slice(1, 8, 2) selects every second character from index 1 to 7.