🌐
GeeksforGeeks
geeksforgeeks.org › python › string-slicing-in-python
String Slicing in Python - GeeksforGeeks
Negative indexing makes it easy to get items without needing to know the exact length of the string. ... s[-4:] slices the string starting from the 4th character from the end ('m') to the end of the string.
Published: July 12, 2025
🌐
W3Schools
w3schools.com › python › python_strings_slicing.asp
Python - Slicing Strings
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 the string. Get the characters from position 2 to position 5 (not included):
Discussions

python - Slice to the end of a string without using len() - Stack Overflow
With string indices, is there a way to slice to end of string without using len()? Negative indices start from the end, but [-1] omits the final character. word = "Help" word[1:-1] # But I More on stackoverflow.com
🌐 stackoverflow.com
how to slice a string from the end
>>> foo = "file.txt" >>> foo[:] 'file.txt' >>> foo[1:] 'ile.txt' >>> foo[-4] '.' >>> foo[-4:] '.txt' More on reddit.com
🌐 r/learnprogramming
28
2
February 19, 2023
String slice explanation, please? I don't understand the output.
It seems that you don't understand the meaning of "step". I will explain: In the third row, you have inserted a step value of 2. This means you will begin at the character 3 and end at character 7, printing every other character (3,5,7) In the fourth row, you will print every third character beginning at 3 (3,6). Keep in mind that your "stop" value is not inclusive, so your string slice will only go up to position 7 in the string More on reddit.com
🌐 r/learnpython
8
3
April 3, 2016
Why slices work the way they are?
I'm really curious what is justification for it working that way. There's a lot of good reasons to have half-open intervals , not the least of which is "Edgar Dijkstra told us to", but another good reason is that the half-open interval p:q of the elements of L has a length exactly equal to q-p. There's a lot of fencepost errors avoided by making everyone use half-open intervals. More on reddit.com
🌐 r/learnpython
61
136
September 10, 2020
🌐
Reddit
reddit.com › r/learnprogramming › how to slice a string from the end
r/learnprogramming on Reddit: how to slice a string from the end
February 19, 2023 -

hi, i'm playing with string slice and i don't understand some things. i know that the [-1] is the last charachter, [-2] the penultimate etc. so, i have a string like "file.txt" and i want to exctract only the ".txt" part of it. i tried with string[-1:-4] but i get an empty string; then i tried with string[:len(string)-5:-1] but i get "txt.". i don't know what i'm doing wrong, can someone explain it to me? thank you

Problem with String Slicing in Python Aug 27, 2022
r/learnprogramming
4y ago
A Comprehensive Guide to Slicing in Python Feb 1, 2022
r/Python
4y ago
How to split a string based on this pattern? Feb 28, 2023
r/learnpython
3y ago
How exactly should a String.split() function behave? Mar 26, 2018
r/ProgrammingLanguages
8y ago
Can someone explain string splicing in detail? Aug 13, 2021
r/learnpython
5y ago
More results from reddit.com
🌐
LearnPython.com
learnpython.com › blog › string-slicing-in-python
String Slicing in Python: A Complete Guide | LearnPython.com
April 15, 2024 - In this example, we create the slice using [1:], which includes all the characters from the second one up to the end of the string. We can also use negative index values to slice a string in Python. Let’s say we need to extract a slice to include the last 6 characters.
🌐
Learn By Example
learnbyexample.org › python-string-slicing
Python String Slicing - Learn By Example
April 20, 2020 - # Slice first three characters from the string S = 'ABCDEFGHI' print(S[:3]) # ABC · Whereas, omitting the stop index extends the slice to the end of the string.
🌐
W3Schools
w3schools.com › python › gloss_python_string_slice.asp
Python Slice Strings
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 the string. Get the characters from position 2 to position 5 (not included):
Find elsewhere
🌐
How to Use Linux
howtouselinux.com › home › 3 ways to slice string in python
3 ways to Slice String in Python - howtouselinux
October 9, 2025 - We define a slice by using square brackets, a start offset, an end offset, and an optional step count between them. ... [ start : end : step ] extracts from the start offset to the end offset minus 1, skipping characters by step. Python’s slicing syntax allows you to extract a substring from ...
🌐
AskPython
askpython.com › python › string › slice-strings-in-python
How to Slice Strings in Python? - AskPython
August 6, 2022 - We can easily slice a given string by mentioning the starting and ending indices for the desired sub-string we are looking for. Look at the example given below, it explains string slicing using starting and ending indices for both usual and ...
🌐
freeCodeCamp
freecodecamp.org › news › python-substring-how-to-slice-a-string
Python Substring – How to Slice a String
July 27, 2021 - In this example, you will slice the last 4 characters from the string. Here you use the negative index to start slicing from the end of the string.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-slice-string
Python slice string | DigitalOcean
Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
Pierian Training
pieriantraining.com › home › string slicing in python: a beginner’s guide
String Slicing in Python: A Beginner's Guide - Pierian Training
April 28, 2023 - In Python, we can use square brackets and the colon (:) to slice a string. ... Here, `start` is the index of the first character we want to include in our slice. `end` is the index of the first character we want to exclude from our slice.
🌐
Python Central
pythoncentral.io › cutting-and-slicing-strings-in-python
Cutting and slicing strings in Python - Python Central
September 6, 2023 - The first index, if omitted, defaults to 0, so that your chunk starts from the beginning of the original string; the second defaults to the highest position in the string, so that your chunk ends at the end of the original string. Omitting both indices isn't likely to be of much practical use; as you might guess, it simply returns the whole of the original string. [python] >>> s[4:] 'Quijote' # Returns from pos 4 to the end of the string >>> s[:4] 'Don ' # Returns from the beginning to pos 3 >>> s[:] 'Don Quijote' [/python]
🌐
Linode
linode.com › docs › guides › how-to-slice-and-index-strings-in-python
How to Slice and Index Strings in Python | Linode Docs
January 28, 2022 - A stride of 2 tells Python to select every second character. A stride of -2, however, indicates that every second letter should be selected from right to left. The stride is specified as an optional third argument to the slice operation using the format string[starting_position:ending_postio...
🌐
Upskillcampus
upskillcampus.com › home › slicing strings in python: a step-by-step tutorial
Slicing Strings in Python: A Step-by-Step Tutorial - Latest Insights & Guides | Career Upskilling Blogs
January 2, 2025 - It assumes the start is 0 and the step is 1. So, it starts from the beginning and goes through the iterable one item at a time. Slice(start, stop, step) – This version is more flexible. You can specify all three parameters: start, stop, and step. Moreover, this gives you full control over where the slicing begins, and ends, and how it iterates through the iterable. In short, the slice() method grabs specific parts of a sequence easily based on your needs. String slicing in Python is a simple yet powerful tool to extract parts of a string.
🌐
Real Python
realpython.com › lessons › string-slicing
String Slicing (Video) – Real Python
When doing string slicing, you can also specify a stride in your string slice. 05:46 It’s adding an additional colon (:) and a third index designates what the stride will be. It’s also called a step. So in this case, if our slice was from the beginning, 0, to the end of our string here, 7, and then followed a step of 2, it would start with the very first item, which is 0, and then skip—taking two steps—to grab index 2, and then skip ahead two, and grab index 4, and then go to the end here, index 6.
Published: October 1, 2019
🌐
Mimo
mimo.org › tutorials › python › how-to-slice-a-string-in-python
How to Slice a String in Python
Learn how to slice a string in Python with s[start:end] and s[start:end:step] so you can extract prefixes, suffixes, ranges, or patterns without loops.
🌐
YouTube
youtube.com › watch
🐍 Python Tutorial #26: String Slicing - YouTube
Learn how to master string slicing in Python with this easy-to-follow tutorial! String slicing allows you to extract parts of strings (substrings) using simp...
Published: June 28, 2025
🌐
Manifoldapp
cuny.manifoldapp.org › read › how-to-code-in-python-3 › section › 93337ae8-329e-493b-b15a-7fe26f12f037
How To Index and Slice Strings | How To Code in Python 3 | Manifold @CUNY
To print a substring that starts in the middle of a string and prints to the end, we can do so by including only the index number before the colon, like so: ... By including only the index number before the colon and leaving the second index number out of the syntax, the substring will go from ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python string slice with examples
Python String Slice with Examples - Spark By {Examples}
May 21, 2024 - To slice from a string in Python use str[] and sometimes str. In this article, we will discuss two ways to return the substring from the string through a