🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-slicing
Python List Slicing - GeeksforGeeks
In Python, list slicing allows out-of-bound indexing without raising errors. If we specify indices beyond the list length then it will simply return the available items. Example: The slice a[7:15] starts at index 7 and attempts to reach index ...
Published   July 23, 2025
🌐
Python Morsels
pythonmorsels.com › slicing
List slicing in Python - Python Morsels
March 8, 2024 - In Python, slicing looks like indexing with colons (:). You can slice a list (or any sequence) to get the first few items, the last few items, or all items in reverse.
Discussions

I am confused about Slicing a List.
No. players[0:3] means "start at index 0, go until index 3-1", so that's the first 3 elements of your list. If you want the last 3 you need to use negative indexes. print(players[-3:]) More on reddit.com
🌐 r/learnpython
17
1
February 11, 2025
Why isn't slicing out of range?
Hi, First of all, please understand that I wrote it using a translator. I’m using Python version 3.11.1 alpha=‘abcdef’ alpha[7] => out of range alpha[0:99] => ‘abcdef’ If you look at the above, indexing causes errors when out of range, but slicing does not cause errors when out of index. More on discuss.python.org
🌐 discuss.python.org
1
February 9, 2023
python - Slicing a list starting from given index and jumping/stepping it with some integer - Stack Overflow
I have the general idea of how to do this in php, but I am new to Python and not sure how to do it. I am trying to implement a function that returns a list containing every second element of every... More on stackoverflow.com
🌐 stackoverflow.com
Slicing list of lists in Python - Stack Overflow
Why? he needs the first idx elements from each list. 2016-04-05T20:32:37.85Z+00:00 ... @WayneWerner correct but I changed the meaning of idx...instead of the slice it's a raw int 2016-04-05T20:33:12.493Z+00:00 More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-slicing-list-from-kth-element-to-last-element
Python - Slicing List from Kth Element to Last Element - GeeksforGeeks
July 11, 2025 - For example, n = [10, 20, 30, 40, ... should be [30, 40, 50]. List slicing allows extracting a portion of a list using the syntax list[k:] which retrieves all elements from Kth index to end....
🌐
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 syntax.
🌐
Bas
bas.codes › posts › python-slicing
A Comprehensive Guide to Slicing in Python - Bas codes
January 31, 2022 - Since we’re using Nones, the slice object needs to calculate the actual index values based on the length of our sequence. Therefore, to get our index triple, we need to pass the length to the indices method, like so: ... This will give us the triple (0, 6, 2). We now can recreate the loop like so: sequence = list("Python") start = 0 stop = 6 step = 2 i = start while i != stop: print(sequence[i]) i = i+step
Find elsewhere
🌐
Replit
replit.com › home › discover › how to slice a list in python
How to slice a list in Python
4 weeks ago - This allows you to work backward without knowing the list's length. The slice numbers[-4:-1] starts at the fourth-to-last element (6) and stops just before the last element, yielding [6, 7, 8]. Omitting the stop index, as in numbers[-3:], tells Python to slice from the third-to-last element all the way to the end.
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.3 documentation
Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key. You can’t use lists as keys, since lists can be modified in place using index assignments, slice assignments, or methods like append() and extend().
🌐
Python.org
discuss.python.org › python help
Why isn't slicing out of range? - Python Help - Discussions on Python.org
February 9, 2023 - Hi, First of all, please understand that I wrote it using a translator. I’m using Python version 3.11.1 alpha=‘abcdef’ alpha[7] => out of range alpha[0:99] => ‘abcdef’ If you look at the above, indexing causes errors when out of range, but slicing does not cause errors when out of index.
🌐
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.
🌐
Canard Analytics
canardanalytics.com › blog › python-list-slicing
A Guide to Python List Slicing | Canard Analytics
June 8, 2022 - A sub-list can be quickly and easily extracted from a list without the need to loop through the items in the list. There are two ways to slice a list in Python; using what we call slice notation [start:stop:step] or using the slice(start,stop,step) method.
🌐
Sentry
sentry.io › sentry answers › python › slicing in python
Slicing in Python | Sentry
May 15, 2023 - 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 ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › slice-a-2d-list-in-python
Slice a 2D List in Python - GeeksforGeeks
July 23, 2025 - import numpy as np # Convert the ... ... In conclusion, slicing a 2D list in Python allows for efficient extraction of specific elements or sublists based on specified ranges....
🌐
Ceos3c
ceos3c.com › home › python › python list slicing – simplified
Python List Slicing - Simplified
October 6, 2022 - Python list slicing is a process of selecting a specific range of items from a Python list. This can be done by specifying the starting and ending indices or by using Python slice notation.
🌐
The Python Coding Stack
thepythoncodingstack.com › p › a-python-slicing-story
A Slicing Story - by Stephen Gruppetta
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.
Top answer
1 of 5
199

The short answer

Slicing lists does not generate copies of the objects in the list; it just copies the references to them. That is the answer to the question as asked.

The long answer

Testing on mutable and immutable values

First, let's test the basic claim. We can show that even in the case of immutable objects like integers, only the reference is copied. Here are three different integer objects, each with the same value:

>>> a = [1000 + 1, 1000 + 1, 1000 + 1]

They have the same value, but you can see they are three distinct objects because they have different ids:

>>> map(id, a)
[140502922988976, 140502922988952, 140502922988928]

When you slice them, the references remain the same. No new objects have been created:

>>> b = a[1:3]
>>> map(id, b)
[140502922988952, 140502922988928]

Using different objects with the same value shows that the copy process doesn't bother with interning -- it just directly copies the references.

Testing with mutable values gives the same result:

>>> a = [{0: 'zero', 1: 'one'}, ['foo', 'bar']]
>>> map(id, a)
[4380777000, 4380712040]
>>> map(id, a[1:]
... )
[4380712040]

Examining remaining memory overhead

Of course the references themselves are copied. Each one costs 8 bytes on a 64-bit machine. And each list has its own memory overhead of 72 bytes:

>>> for i in range(len(a)):
...     x = a[:i]
...     print('len: {}'.format(len(x)))
...     print('size: {}'.format(sys.getsizeof(x)))
... 
len: 0
size: 72
len: 1
size: 80
len: 2
size: 88

As Joe Pinsonault reminds us, that overhead adds up. And integer objects themselves are not very large -- they are three times larger than references. So this saves you some memory in an absolute sense, but asymptotically, it might be nice to be able to have multiple lists that are "views" into the same memory.

Saving memory by using views

Unfortunately, Python provides no easy way to produce objects that are "views" into lists. Or perhaps I should say "fortunately"! It means you don't have to worry about where a slice comes from; changes to the original won't affect the slice. Overall, that makes reasoning about a program's behavior much easier.

If you really want to save memory by working with views, consider using numpy arrays. When you slice a numpy array, the memory is shared between the slice and the original:

>>> a = numpy.arange(3)
>>> a
array([0, 1, 2])
>>> b = a[1:3]
>>> b
array([1, 2])

What happens when we modify a and look again at b?

>>> a[2] = 1001
>>> b
array([   1, 1001])

But this means you have to be sure that when you modify one object, you aren't inadvertently modifying another. That's the trade-off when you use numpy: less work for the computer, and more work for the programmer!

2 of 5
32

Depending on what you're doing, you might be able to use islice.

Since it operates via iteration, it won't make new lists, but instead will simply create iterators that yield elements from the original list as requested for their ranges.