You can instead try using:
word[1:]
Answer from Uku Loskit on Stack OverflowGeeksforGeeks
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
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
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
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
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
00:59
why python string slices IGNORE end elements - pythontutor.com ...
00:59
it's odd to slice a python string BACKWARDS - pythontutor.com - ...
Python String Slicing
05:06
Reversing Strings in Python with Slicing - YouTube
13:10
Python Slicing String and List | Python Slice Notation Explained ...
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
Top answer 1 of 4
4
>>> foo = "file.txt" >>> foo[:] 'file.txt' >>> foo[1:] 'ile.txt' >>> foo[-4] '.' >>> foo[-4:] '.txt'
2 of 4
1
Try "." + (string.split(".")[-1])
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):
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 ...
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 ...