🌐
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 ... 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 second element (index 1), which correspond to the even numbers in the list...
🌐
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 - ... >>> nums = [10, 20, 30, 40, 50, 60, 70, 80, 90] >>> some_nums = nums[2:7] >>> some_nums [30, 40, 50, 60, 70] So, here is our first example of a slice: 2:7. The full slice syntax is: start:stop:step. start refers to the index of the element ...
Discussions

So confused about indexing
Or if you wonder why you would write 4 to get first four characters, line in "programming"[:4], it's because the stop index is not included in the slice. So to get slice of items #0 to 3, you specify 3 + 1, which is 4. More on reddit.com
🌐 r/learnpython
12
0
August 21, 2022
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
On negative step, the default start and stop are reversed. Start is len-1 stop is 0. More on reddit.com
🌐 r/learnpython
5
2
December 15, 2021
Is string slicing actually useful in real world applications?
If you are doing lot of text processing, then yes. Here's an example from my usecase. I have markdown files with code snippets starting with $ or >>> etc. I have to post process those files to extract only the command that comes after the prompt. Easiest solution is string slicing, since the length of the prompt is fixed. Also, slicing in Python can be applied to lists, tuples, strings, etc. So, even if you are not doing text processing, you can apply the knowledge elsewhere. More on reddit.com
🌐 r/learnpython
8
1
October 13, 2020
🌐
Medium
medium.com › @shilpasree209 › indexing-slicing-in-python-f45d9caed433
Indexing & Slicing in Python!!!. These 2 things are interesting terms… | by Shilpa Sreekumar | Medium
January 23, 2024 - As seen in the example above, you can notice that there are 3 key concepts in indexing: Zero-based indexing : Python starts counting indices from 0, not 1. So, the first element has an index of 0, the second has an index of 1, and so on.
🌐
W3Schools
w3schools.com › python › python_strings_slicing.asp
Python - Slicing Strings
Get the characters from position 2, and all the way to the end: b = "Hello, World!" print(b[2:]) Try it Yourself » · Use negative indexes to start the slice from the end of the string:
🌐
Practicise
practicise.com › home › lessons › string indexing and slicing
Python - String Indexing and Slicing
November 12, 2024 - You can also specify a step value in slicing, which will determine how many steps the slice should skip between indices. ... text = "Python" # Extract every second character (step = 2) print(text[::2]) # "Pto" (characters at indices 0, 2, and 4) # Extract the string in reverse order (step = -1) print(text[::-1]) # "nohtyP" # Extract characters from index 1 to 5, with a step of 2 print(text[1:5:2]) # "yhn"
🌐
Real Python
realpython.com › lessons › indexing-and-slicing
Indexing and Slicing (Video) – Real Python
So in this example, if a is your list, then inside your square brackets you would have your two index numbers separated by a colon (:), and it’s going to return a portion of that a list that will start with position m and go up to but not include index n. 02:38 Using that same example from before, if you took a[2:5], you’d get the three objects in the middle, starting at index 2 and going up to index 4, but not including 5. 02:50 Let me have you try it out. Okay, so here’s your list. What if you wanted to slice?
Published: September 3, 2019
🌐
TutorialsPoint
tutorialspoint.com › article › difference-between-indexing-and-slicing-in-python
Difference between indexing and slicing in Python
September 15, 2022 - # input list input_list = [1, 4, 8, 6, 2] # This will throw an IndexError print("Element at index 10:", input_list[10]) ... The term slicing refers to obtaining a subset of elements from a sequence based on their indices.
🌐
Towards Data Science
towardsdatascience.com › home › latest › mastering indexing and slicing in python
Mastering Indexing and Slicing in Python | Towards Data Science
January 19, 2025 - Slicing expressions in Python come with a third index which is optional and when specified is used as a step. Obviously, when the step value is omitted it defaults to 1 which means that no element in the requested sequence sub-section will be ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-index-and-slice-strings-in-python
How to Index and Slice Strings in Python? - GeeksforGeeks
July 15, 2025 - In this type of Indexing, we pass the Negative index(which we want to access) in square brackets. Here the index number starts from index number -1 (which denotes the last character of a string). Example 2 (Negative Indexing) :
🌐
Career Bodh Sansthan
careerbodh.in › post › what-is-slicing-and-indexing-in-python-with-examples
What is slicing and indexing in Python with examples?
February 17, 2022 - Slice () function returns a slice object used to slice a sequence in the given indices. ... In our example it start from value 20 and stop is 35, here we are passing positive index then it should be from left to right forward direction . ... Python allows us to rescue individual elements of ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-index-and-slice-strings-in-python-3
How To Index and Slice Strings in Python | DigitalOcean
Learn how to index and slice strings in Python 3 with step-by-step examples. Master substring extraction, negative indexing, and slice notation.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-slicing
Python List Slicing - GeeksforGeeks
... Example 2: In this example, ... copy. ... Explanation: slice a[::-1] starts from the end of the list and moves backward one element at a time, returning a reversed copy of the list....
Published: July 16, 2026
🌐
UC Berkeley Statistics
stat.berkeley.edu › ~spector › extension › python › notes › node19.html
Indexing and Slicing
>>> what = 'This parrot is dead' ... piece of a string (known as a slice), use a subscript consisting of the starting position followed by a colon (:, finally followed by one more than the ending position of the slice you want to extract....
🌐
YouTube
youtube.com › watch
Indexing and Slicing Python Lists for Beginners - YouTube
➡ JOIN MY MAILING LISThttps://johnwrooney.substack.com/➡ COMMUNITYhttps://discord.gg/C4J2uckpbR➡ PROXIEShttps://proxyscrape.com/?ref=jhnwr➡ WEB SCRAPING APIh...
Published: November 20, 2019
🌐
All About AI-ML
indhumathychelliah.com › 2020 › 09 › 22 › indexing-vs-slicing-in-python
Indexing vs Slicing in Python – All About AI-ML
January 2, 2022 - An object usually containing a portion of a sequence.A slice is created using the subscript notation, [] with colons between numbers when several are given, such as in variable_name[1:3:5]. The bracket (subscript) notation uses slice objects ...
🌐
Hostman
hostman.com › tutorials › slicing-and-indexing-strings-in-python
Slicing and Indexing Strings in Python
Each character in a Python string is assigned an index starting from 0 for the first character and incrementing by 1 for each subsequent character. To access a specific character, you simply refer to its index within square brackets.
🌐
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....
🌐
Python for Data Science
python4data.science › en › latest › workspace › numpy › indexing-slicing.html
Indexing and slicing - Python for Data Science
May 15, 2026 - In the following example, I select the rows where names == 'Tim' and also index the columns: ... If you select two of the three names to combine several Boolean conditions, you can use the Boolean arithmetic operators & (and) and | (or). ... The Python keywords and and or do not work with Boolean arrays.
🌐
Just Academy
justacademy.co › blog-detail › difference-between-indexing-and-slicing-in-python
Difference Between Indexing And Slicing In Python by Roshan Chaturvedi | JustAcademy
Indexing in Python is zero-based, meaning the first element in a sequence is accessed using index 0. On the other hand, slicing involves extracting a subset of elements from the sequence by specifying a range of indices, separated by a colon, ...
🌐
Gyansetu
gyansetu.in › data science › string slicing in python with examples
String slicing in Python with Examples - Gyansetu
May 22, 2025 - String slicing is performed by specifying the start and end indices within square brackets, separated by a colon, like this: `string[start:end]`. The result is a new string containing characters from the ‘start’ index up to (but not including) ...