🌐
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 ...
🌐
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
🌐
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 ...
🌐
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):
🌐
LearnPython.com
learnpython.com › blog › string-slicing-in-python
String Slicing in Python: A Complete Guide | LearnPython.com
Python provides more flexible ways to slice a string. By default, string slice includes all the characters between the given starting and ending point. We can change this behavior using the step size parameter. The default value of the step size is 1, which selects every character. If we change it to 2, the string slice contains every other character within the defined sequence. The step size comes after the ending index and is separated from it by another colon.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-index-and-slice-strings-in-python-3
How To Index and Slice Strings in Python | DigitalOcean
September 29, 2025 - Slicing: How to extract a substring (a slice”) from a larger string using the [start:end:step] syntax. We saw how start is inclusive, end is exclusive, and step determines the increment. Key Differences: The distinction between indexing (which returns a single character and raises an IndexError ...
🌐
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

Find elsewhere
🌐
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.
🌐
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 - Pass the start index, end index, and stride as arguments to the constructor. Enclose the slice object in square brackets [] and use it to generate a substring from the parent string as follows.
🌐
CodingNomads
codingnomads.com › string-slicing-in-python
String Slicing in Python
This elegance and user-friendliness of Python's syntax are some of the reasons why it is a great language to pick up. ... Syntax: Inside of square brackets, use an inclusive start index position separated from an exclusive end index position by a colon · Shortcuts: Omit the start or the end index to slice all the way to the start or end of the string, respectively
🌐
AskPython
askpython.com › home › how to 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 ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python string slice with examples
Python String Slice with Examples - Spark By {Examples}
May 21, 2024 - You can also extract a sub-string (also called a “slice”) from a python string using the slice notation with syntax [start:stop:step]. Here, the start index is the starting position of the slice, and the stop index is the ending position ...
🌐
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.
🌐
Enterprise DNA
blog.enterprisedna.co › python-slice-string
Python Slice String: 2 Quick Ways Explained With Examples – Master Data Skills + AI
With Python, slicing string is simple and requires a basic understanding of indexing and strings in Python. To slice a string in Python, you can use the slice() method or employ the array slicing with the [::] notation. Both approaches rely on providing start and end positions, along with an ...
🌐
Python.org
discuss.python.org › python help
Advanced slicing rules? - Python Help - Discussions on Python.org
August 14, 2022 - So I’m taking a quiz and the first question asks something that was never written or spoken once in the section on lists as they pertain to slicing… which is absolutely infuriating as I am someone who tries to understand EVERYTHING before moving on: Question 1: What are the values of list_b and list_c after the following snippet? list_a = [1, 2, 3] list_b = list_a[-2:-1] list_c = list_a[-1:-2] To me this answer would be: list_b = [2,3] list_c = [3,2] … but that is not one of the answer...
🌐
Python Examples
pythonexamples.org › how-to-slice-a-string-in-python
How to Slice a String in Python?
myStr = 'hello-world' start = 2 #start position of slice in string stop = 9 #end position of slice in string step = 2 slice_object = slice(start, stop, step) result = myStr[slice_object] print(result) ... The slice object would contain the indices [2, 4, 6, 8]. And the characters in the string corresponding to these indices are [l, o, w, r], Hence the resulting string of 'lowr'. In this tutorial of Python Examples, we learned how to slice a string, using slice() builtin function.
🌐
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
🌐
Python Examples
pythonexamples.org › python-substring-from-specific-index-to-end
Substring from Index to End in Python
In the following example, we will take a string in mystring, and get the substring that starts at the index 6, and ends at the end of the given string. mystring = 'pythonexamples.org' index = 6 substring = mystring[index:] print(substring)
🌐
Python.org
discuss.python.org › python help
Question about string sequencing and slicing - Python Help - Discussions on Python.org
July 16, 2022 - Hi I’ve just begun learning how to code in python and have come across string sequencing and slicing. I’m having trouble understanding the concept of the 0. For example, If I were to sequence the string “Michael Jackson” the python would assign the M=0 I=1 C=2 H=3 A=4 and so and so forth.