๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_strings_slicing.asp
Python - Slicing Strings
Use negative indexes to start the slice from the end of the string: ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com ยท HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-slice-string
Python slice string | DigitalOcean
August 3, 2022 - Python String slicing always follows this rule: s[:i] + s[i:] == s for any index โ€˜iโ€™. All these parameters are optional - start_pos default value is 0, the end_pos default value is the length of string and step default value is 1. Letโ€™s look at some simple examples of string slice function to create substring.
Discussions

slice - How slicing in Python works - Stack Overflow
How does Python's slice notation work? That is: when I write code like a[x:y:z], a[:], a[::2] etc., how can I understand which elements end up in the slice? See Why are slice and range upper-bound More on stackoverflow.com
๐ŸŒ stackoverflow.com
Mesh slicing in Python (for eventual Gcode generation)

In general I advise using a library. You're working with real-world data here so if you want to do the slicing yourself you'll have to reinvent a fair chunk of the library because you'll need to handle all the quirks and problems that result from a simplistic approach. That said, I'm willing to help you build your own slicer if you insist.

You have a 3x3xN array. Is this a numpy.ndarray? You can try calling type() on your object if you're not sure.

Do you have to process a lot of these? Can you give me a general idea of how large N is?

More on reddit.com
๐ŸŒ r/learnpython
5
1
May 28, 2015
Does array slicing [::] use extra memory?
Python list slicing should be creating a new list (use more memory). You can see the implementation of that here . I think what you read regarding slicing may be for NumPy arrays where slices create โ€œviewsโ€ and not copies. More on reddit.com
๐ŸŒ r/Python
9
3
December 13, 2021
Slicing STL Files and analyzing GCODE
I made a script that slices an STL file with the given settings and extracts the printing time and filament consumed. It is my first real pythonโ€ฆ More on reddit.com
๐ŸŒ r/Python
1
May 4, 2018
๐ŸŒ
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 - I can relate to this! I also use `[...][...]` (two-slice) notation most of the time for these cases.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ functions.html
Built-in Functions โ€” Python 3.14.3 documentation
3 days ago - Return a slice object representing the set of indices specified by range(start, stop, step).
๐ŸŒ
DEV Community
dev.to โ€บ thrivensunshine โ€บ slicing-in-python-2hlk
Slicing in Python - DEV Community
April 3, 2020 - One of these similarities include the idea of "slicing" some form of data. Slicing does exactly what it implies, it "slices" up data into smaller parts. Every language has their own particular way of doing this.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-list-slicing
Python List Slicing - GeeksforGeeks
Python list slicing is fundamental concept that let us easily access specific elements in a list.
Published ย  July 23, 2025
๐ŸŒ
Medium
medium.com โ€บ @yeaske โ€บ slicing-in-python-the-basics-e812cb5bfd7a
โ€˜Slicingโ€™ in Python: The Basics
December 30, 2022 - To slice a sequence in Python, you use the square brackets [] and specify a range of indices separated by a colon :. The syntax for slicing is sequence[start:end:step], where start is the index of the first element to include in the slice, end ...
Find elsewhere
๐ŸŒ
Python Reference
python-reference.readthedocs.io โ€บ en โ€บ latest โ€บ docs โ€บ brackets โ€บ slicing.html
[] (slicing) โ€” Python Reference (The Right Way) 0.1 documentation
>>> +---+---+---+---+ >>> |-4 |-3 |-2 |-1 | <= negative indexes >>> +---+---+---+---+ >>> | A | B | C | D | <= sequence elements >>> +---+---+---+---+ >>> | 0 | 1 | 2 | 3 | <= positive indexes >>> +---+---+---+---+ >>> |<- 0:3:1 ->| <= extent of the slice: "ABCD"[0:3:1]
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ home โ€บ python โ€บ python string slicing
Python String Slicing
February 21, 2009 - Python String slicing is a way of creating a sub-string from a given string. In this process, we extract a portion or piece of a string. Usually, we use the slice operator "[ : ]" to perform slicing on a Python String.
๐ŸŒ
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.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.3 documentation
There is a way to remove an item from a list given its index instead of its value: the del statement. This differs from the pop() method which returns a value. The del statement can also be used to remove slices from a list or clear the entire list (which we did earlier by assignment of an empty list to the slice).
๐ŸŒ
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
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-slicing-how-to-slice-an-array
Python Slicing โ€“ How to Slice an Array and What Does [::-1] Mean?
December 8, 2022 - In our example, the start is 1, the end is 4 and the step is 2. Slicing starts from the value at index 1 which is 2, then the next value will be at the previous index plus the step, which is 1 + 2 equals 3. The value at index 3 is 4 so that is added to the slice.
๐ŸŒ
Python Reference
python-reference.readthedocs.io โ€บ en โ€บ latest โ€บ docs โ€บ functions โ€บ slice.html
slice โ€” Python Reference (The Right Way) 0.1 documentation
Slice objects have read-only data attributes start, stop and step which merely return the argument values (or their default). They have no other explicit functionality; however they are used by Numerical Python and other third party extensions. Slice objects are also generated when extended ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_slice.asp
Python slice() Function
A slice object is used to specify how to slice a sequence. You can specify where to start the slicing, and where to end. You can also specify the step, which allows you to e.g.
๐ŸŒ
Pandas
pandas.pydata.org โ€บ pandas-docs โ€บ stable โ€บ user_guide โ€บ indexing.html
Indexing and selecting data โ€” pandas 3.0.1 documentation
The semantics follow closely Python and NumPy slicing. These are 0-based indexing. When slicing, the start bound is included, while the upper bound is excluded. Trying to use a non-integer, even a valid label will raise an IndexError. The .iloc attribute is the primary access method. The following are valid inputs: An integer e.g. 5. A list or array of integers [4, 3, 0]. A slice object with ints 1:7.
๐ŸŒ
Ramisayar
ramisayar.com โ€บ hidden-features-in-python-slicing-and-sliding
Neat Features in Python: Slicing and Sliding (Stepping) - Rami Sayar
So what is sliding or stepping? Sliding allows you to specify an increment between the elements to cut from your list. If you wanted to slice every 2 elements, instead of specifying an increment of 1, you specify 2.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ introduction.html
3. An Informal Introduction to Python โ€” Python 3.14.3 documentation
The first row of numbers gives the position of the indices 0โ€ฆ6 in the string; the second row gives the corresponding negative indices. The slice from i to j consists of all characters between the edges labeled i and j, respectively.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ reference โ€บ datamodel.html
3. Data model โ€” Python 3.14.3 documentation
This method takes a single integer argument length and computes information about the slice that the slice object would describe if applied to a sequence of length items. It returns a tuple of three integers; respectively these are the start ...
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.