๐ŸŒ
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 Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... You can return a range of characters by using the slice ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_slice.asp
Python slice() Function
Remove List Duplicates Reverse a String Add Two Numbers ยท Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Create a tuple and a slice object.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-list-slicing
Python List Slicing - GeeksforGeeks
Explanation: The negative step (-1) indicates that Python should traverse the list in reverse order, starting from the end. The slice a[::-1] starts from the end of the list and moves to the beginning which result in reversing list.
Published ย  July 23, 2025
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_slicing.asp
NumPy Array Slicing
Slicing in python means taking elements from one given index to another given index. We pass slice instead of index like this: [start:end].
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_string_slice.asp
Python Slice Strings
Remove List Duplicates Reverse a String Add Two Numbers ยท Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... You can return a range of characters by using the slice ...
๐ŸŒ
W3Schools
w3schoolsua.github.io โ€บ python โ€บ python_strings_slicing_en.html
Python - Slicing Strings. Lessons for beginners. W3Schools in English
Remove List Duplicates Reverse a String Add Two Numbers ยท Python Examples Python Compiler Python Exercises Python Quiz Python Bootcamp Python Certificate ... You can return a range of characters by using the slice syntax.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Slicing Strings in Python - Python Tutorial - w3Schools - Ch#10 English - YouTube
Slicing - 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...
Published ย  July 18, 2022
๐ŸŒ
Learn By Example
learnbyexample.org โ€บ python-list-slicing
Python List Slicing - Learn By Example
June 20, 2024 - Learn to slice a list with positive & negative indices in Python, modify insert and delete multiple list items, reverse a list, copy a list and more.
Find elsewhere
Top answer
1 of 16
6657

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.

๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_lists.asp
Python Lists
List is a collection which is ordered and changeable. Allows duplicate members. Tuple is a collection which is ordered and unchangeable. Allows duplicate members. Set is a collection which is unordered, unchangeable*, and unindexed. No duplicate members. Dictionary is a collection which is ordered** and changeable. No duplicate members. *Set items are unchangeable, but you can remove and/or add items whenever you like. **As of Python version 3.7, dictionaries are ordered.
๐ŸŒ
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: ... element at the end_index). To slice a sequence, you can use square brackets [] with the start and end indices separated by a colon....
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ slicing
List slicing in Python - Python Morsels
March 8, 2024 - Let's talk about slicing lists in Python. Let's say we have a fruits variable that points to a list: >>> fruits = ['watermelon', 'apple', 'lime', 'kiwi', 'pear', 'lemon', 'orange'] >>> fruits ['watermelon', 'apple', 'lime', 'kiwi', 'pear', 'lemon', 'orange'] ... If we put a colon and another number inside the square brackets, we'll slice this list instead of indexing it:
๐ŸŒ
Python
docs.python.org โ€บ 2.3 โ€บ whatsnew โ€บ section-slices.html
https://docs.python.org/2.3/whatsnew/section-slice...
Extended slices aren't this flexible. When assigning to an extended slice, the list on the right hand side of the statement must contain the same number of items as the slice it is replacing:
๐ŸŒ
Kansas State University
textbooks.cs.ksu.edu โ€บ intro-python โ€บ 07-lists โ€บ 05-slicing-lists
Slicing Lists :: Introduction to Python
June 27, 2024 - Since a range can be constructed from just three numbers, it is much simpler to store just those numbers in memory instead of the entire list of numbers that it represents. When we create a slice of a range object, it just generates a new range instead of a list. So, to actually convert a range to a list, we must use the list() function in Python:
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-slice
Python Slice: Useful Methods for Everyday Coding | DataCamp
January 15, 2025 - Pythonโ€™s slice() function provides an alternative definition of slicing parameters as reusable slice objects. These objects encapsulate slicing logic and can be applied across multiple sequences. ... # Create a slice object slice_obj = slice(1, 4) # Apply to a list numbers = [10, 20, 30, 40, 50] print(numbers[slice_obj]) # Output: [20, 30, 40] # Apply to a string text = "Python" print(text[slice_obj]) # Output: "yth"
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ examples โ€บ list-slicing
Python Program to Slice Lists
This is similar to print(my_list). ... If you want to get all the elements after a specific index, you can mention that index before : as shown in example above. In the above example, elements at index 2 and all the elements after index 2 are printed. Note: Indexing starts from 0. Item on index 2 is also included. ... This example lets you get all the elements before a specific index. Mention that index after :. In the example, the items before index 2 are sliced.
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ python โ€บ slicing in python
Slicing in Python | Sentry
The syntax for a simple slice is as follows: ... my_list = [0,1,2,3,4,5,6,7,8,9] start = 1 stop = 5 sublist = my_list[start:stop] # i.e. my_list[1:5] print(sublist) # will print "[1, 2, 3, 4]" Sequences in Python are 0-indexed, and slices are ...
๐ŸŒ
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.
๐ŸŒ
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 both returns a new list that is a subset of the original list.