>>> from operator import itemgetter
>>> a = range(100)
>>> itemgetter(5,13,25)(a)
(5, 13, 25)
Answer from John La Rooy on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-slicing
Python List Slicing - GeeksforGeeks
end (optional): Index to end the slice (exclusive). Defaults to the length of list if omitted. step (optional): Step size, specifying the interval between elements. Defaults to 1 if omitted · 1. Get All Items: If you want to create a copy of the entire list or access all its elements, you can use slicing without specifying any indices. Python ·
Published: July 16, 2026
Discussions

Python List Slicing with Arbitrary Indices - Stack Overflow
Is there a better way to extract arbitrary indices from a list in python? ... Where a is the array I want to slice, and [5,13,25] are the elements that I want to get. More on stackoverflow.com
🌐 stackoverflow.com
How to slice a list from an element n to the end in Python? - Stack Overflow
To my understanding, slice means lst[start:end], and including start, excluding end. So how would I go about finding the "rest" of a list starting from an element n? More on stackoverflow.com
🌐 stackoverflow.com
Slicing list of lists in Python - Stack Overflow
This is very clear. For every sublist in A, give me the list of the first three elements. ... Save this answer. ... Show activity on this post. With numpy it is very simple - you could just perform the slice: More on stackoverflow.com
🌐 stackoverflow.com
python - How does assignment work with list slices? - Stack Overflow
Python docs says that slicing a list returns a new list. Now if a "new" list is being returned I've the following questions related to "Assignment to slices" a = [1, 2, 3] a[0:2... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python Morsels
pythonmorsels.com › slicing
Python list slicing (with examples) - 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....
🌐
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 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 slice syntax.
🌐
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.
🌐
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.
Find elsewhere
🌐
Railsware
railsware.com › home › engineering › indexing and slicing for lists, tuples, strings, other sequential types in python
Python Indexing and Slicing for Lists, Tuples, Strings, other Sequential Types | Railsware Blog
January 22, 2025 - In short, slicing is a flexible tool to build new lists out of an existing list. Python supports slice notation for any sequential data type like lists, strings, tuples, bytes, bytearrays, and ranges.
🌐
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
🌐
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 (excluding the element at the end_index). To slice a sequence, you can use square brackets [] with the start and end indices separated by a colon...
🌐
Kansas State University
textbooks.cs.ksu.edu › intro-python › 07-lists › 05-slicing-lists
Slicing Lists :: Introduction to Python
July 30, 2026 - A slice is simply a portion of a list that can be stored and used as a separate list, allowing us as programmers to quickly create and manipulate new lists based on existing lists. There are two basic ways to create a list slice in Python. nums[start:end] - this will create a slice of the list ...
🌐
Prasad Ostwal
ostwalprasad.github.io › machine-learning › Python-List-Slicing-Cheatsheet.html
Python List Slicing Cheatsheet ·
August 8, 2019 - list[-7::2] >> ['C', 'E', 'G', 'I'] list[-7::3] >> ['C', 'F', 'I'] list[1::-1] >> ['B', 'A'] list[1::-2] >> ['B'] list[1::-7] >> ['B'] list[6::-3] >> ['G', 'D', 'A'] If you have any more patterns, ideas or suggestions, please share. You can fork/start this at https://github.com/ostwalprasad/PythonListSlicingCheatsheet Want to build own site like this within 5 minutes?
🌐
YouTube
youtube.com › watch
List Slicing in Python EXPLAINED - YouTube
🐍 ADVANCED LIST SLICING in Python | Python Lists, List Indexing, List Methods, Assignment, List Concatenation 📚Welcome back to our Python programming journ...
Published: July 18, 2023
Top answer
1 of 5
165

You are confusing two distinct operation that use very similar syntax:

1) slicing:

b = a[0:2]

This makes a copy of the slice of a and assigns it to b.

2) slice assignment:

a[0:2] = b

This replaces the slice of a with the contents of b.

Although the syntax is similar (I imagine by design!), these are two different operations.

2 of 5
101

When you specify a on the left side of the = operator, you are using Python's normal assignment, which changes the name a in the current context to point to the new value. This does not change the previous value to which a was pointing.

By specifying a[0:2] on the left side of the = operator, you are telling Python you want to use slice assignment. Slice assignment is a special syntax for lists, where you can insert, delete, or replace contents from a list:

Insertion:

>>> a = [1, 2, 3]
>>> a[0:0] = [-3, -2, -1, 0]
>>> a
[-3, -2, -1, 0, 1, 2, 3]

Deletion:

>>> a
[-3, -2, -1, 0, 1, 2, 3]
>>> a[2:4] = []
>>> a
[-3, -2, 1, 2, 3]

Replacement:

>>> a
[-3, -2, 1, 2, 3]
>>> a[:] = [1, 2, 3]
>>> a
[1, 2, 3]

Note:

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. - source

Slice assignment provides similar function to tuple unpacking. For example, a[0:1] = [4, 5] is equivalent to:

# Tuple Unpacking
a[0], a[1] = [4, 5]

With tuple unpacking, you can modify non-sequential lists:

>>> a
[4, 5, 3]
>>> a[-1], a[0] = [7, 3]
>>> a
[3, 5, 7]

However, tuple unpacking is limited to replacement, as you cannot insert or remove elements.

Before and after all these operations, a is the same exact list. Python simply provides nice syntactic sugar to modify a list in-place.

🌐
Upgrad
upgrad.com › home › tutorials › software & tech › list slicing in python
List Slicing in Python
July 4, 2026 - Python List Slicing is a technique for extracting specific portions of a list. The syntax for list slicing is: Lst: The list you want to slice.
🌐
Indiachinainstitute
indiachinainstitute.org › wp-content › uploads › 2018 › 05 › Python-Crash-Course.pdf pdf
Python Crash Course
Slicing a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 · Looping Through a Slice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
🌐
Sololearn
sololearn.com › en › Discuss › 3340497 › what-is-slicing-of-data-in-lists-
What is slicing of data in lists
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Canard Analytics
canardanalytics.com › blog › python-list-slicing
A Guide to Python List Slicing | Canard Analytics
June 8, 2022 - # list slice notation sub_list = original_list[start:stop:step] # list slice object sub_list = original_list[slice(start,stop,step)] # The two notations are equivalent