🌐
GeeksforGeeks
geeksforgeeks.org › python › string-slicing-in-python
String Slicing in Python - GeeksforGeeks
It’s especially useful for text manipulation and data parsing. ... Explanation: In this example, we used the slice s[0:5] to obtain the substring "Hello" from the original string.
Published   July 12, 2025
🌐
W3Schools
w3schools.com › python › python_strings_slicing.asp
Python - Slicing Strings
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... You can return a range of characters by using the slice syntax.
Discussions

Explain Python Slice Strings
Learn to Python Slice Strings, slice with positive and negative indices, specify the slicing steps, reverse a string, etc. More on accuweb.cloud
🌐 accuweb.cloud
1
December 6, 2023
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
Today I leaned that in python, slicing a substring with an index that is out of range does not result in an error.
Yeah, the reasoning makes more sense with lists. See this Stack Overflow post: https://stackoverflow.com/a/9490148/4637427 More on reddit.com
🌐 r/learnpython
4
8
March 28, 2024
Python String Slicing
Add the missing forward slashes to the wikipedia URL, or don't use the same slice range for both URLs. More on reddit.com
🌐 r/learnpython
3
4
February 1, 2024
🌐
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
🌐
W3Schools
w3schools.com › python › gloss_python_string_slice.asp
Python Slice Strings
Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... You can return a range of characters by using the slice syntax.
🌐
Tutorialspoint
tutorialspoint.com › python › python_slicing_strings.htm
Python Slicing Strings
In this example, we are performing slice operation using default values. var="HELLO PYTHON" print ("var:",var) print ("var[0:5]:", var[0:5]) print ("var[:5]:", var[:5]) ... Similarly, y operand is also optional.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-slice-string
Python slice string | DigitalOcean
August 3, 2022 - Output: dlroWolleH Let’s look at some other examples of using steps and negative index values. ... Output: loo Here the substring contains characters from indexes 2,4 and 6. ... Output: lroWoll Here the index values are taken from end to start. The substring is made from indexes 1 to 7 from end to start. ... Output: lool Python slice works with negative indexes too, in that case, the start_pos is excluded and end_pos is included in the substring. ... Output: or Python string slicing handles out of range indexes gracefully.
🌐
InterServer
interserver.net › home › python › how to slice strings in python: step-by-step tutorial
How to Slice Strings in Python: Step-by-Step Tutorial - Interserver Tips
April 23, 2026 - The step parameter lets you skip characters in a string. It is written as the third value in the slice: [start:stop:step]. For example, if text = "PythonProgramming", you can get every second character using:
🌐
DataCamp
datacamp.com › tutorial › python-slice
Python Slice: Useful Methods for Everyday Coding | DataCamp
January 15, 2025 - Strings in Python are sequences of characters, which means you can slice them just like lists or tuples. This makes slicing useful for extracting substrings, reversing text, or formatting data. Here I am using :. Basic string slicing# Extract a substring text = "Python Slicing" print(text[7:14]) # Output: Slicing # Reverse a string print(text[::-1]) # Output: gnicilS nohtyP
Find elsewhere
🌐
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 if out of bounds) and slicing (which returns a substring and gracefully handles out-of-bounds requests by returning an empty string). String Reversal: The efficient and Pythonic way to reverse a string using the [::-1] slice.
🌐
Scaler
scaler.com › home › topics › python › string slicing in python
String Slicing in Python with Examples - Scaler Topics
May 17, 2022 - Example 3 – Fetching substring using negative index and negative step value ... There are multiple ways by which string slicing in Python can allow us to reverse a string. Slicing is one of the ways that allows us to reverse a string. The ‘Step’ parameter is considered to be less than 0 when reversing a string. NOTE: When reversing: ‘step’ < 0, ‘start’ > ‘stop’ in slice(start, stop, step).
🌐
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.
🌐
Unstop
unstop.com › home › blog › string slicing in python | syntax & usage with code examples
String Slicing In Python | Syntax & Usage With Code Examples
February 3, 2025 - The example Python program below ... Programming" #Specifying step 2 helps skip to every other character step_slice = string[0:18:2] print(step_slice)...
🌐
iO Flood
ioflood.com › blog › string-slicing-in-python-usage-and-examples
String Slicing in Python: Usage and Examples
November 26, 2023 - Here’s a few more examples of Python string slicing, from eliminating characters from a string to defining all three arguments in a slice.
🌐
Python Guides
pythonguides.com › slicing-string-in-python
How to Perform String Slicing in Python
September 16, 2025 - I executed the above example code and added the screenshot below. Negative indexing makes it very easy to handle strings when the length may vary. Sometimes, I don’t just want a continuous substring. Instead, I may want every second or third character. This is where the step parameter becomes handy. word = "PythonProgramming" skip_one = word[::2] # Every second character reverse_word = word[::-1] # Reverse the string print(skip_one) print(reverse_word)
🌐
The IoT Academy
theiotacademy.co › home › blog › what is slicing strings in python- explained with examples
What is Slicing Strings in Python- Explained with Examples - Tech & Career Blogs
June 16, 2025 - Slicing strings in Python with Positive & Negative Indices It is possible to define both positive and negative indices simultaneously. ... Specify Step for the slice- Using the step parameter, you can define the slicing step. The optional step parameter has a default value of 1. # Return every second item between positions 2 to 7 ... Reversing a String- You can reverse a string by leaving off the start and stop indices and entering a step of -1.
🌐
Real Python
realpython.com › lessons › string-slicing
String Slicing (Video) – Real Python
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. For another example, let’s say you used a slice of [1:7:2].
Published   October 1, 2019
🌐
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 - In this example, we’ll slice the string 'DICTIONARY' to get the substring 'CTION'. ... Here, slicing starts at index 2 and ends just before index 7. The character at index 7 ("A") is not included in the result.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python string slice with examples
Python String Slice with Examples - Spark By {Examples}
May 21, 2024 - # Consider the string st1='Hello welcome to sparkby examples' # Slice starting to 5th character by skipping 3 characters print(st1[slice(0,5,3)]) # Slice 5th to 11th character by skipping 2 characters print(st1[slice(4,11,2)]) # Output: # Hl # owlo
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › string slicing in python
String Slicing in Python | phoenixNAP KB
October 24, 2023 - For example: quote = "There's no place like home." print(quote[slice(None,None,-1)]) The start and stop fields use default values because of the None parameter, while the step value is -1. The code reads the string backward and reverses the ...
🌐
Accuweb
accuweb.cloud › home › explain python slice strings
Explain Python Slice Strings - AccuWeb Cloud
December 6, 2023 - For example, [0:14:2] results in “Pto s”. Negative indices count from the end. Slicing [-6:-1] yields “World.” · You can reverse a string by using [::-1]. For instance, “Python”[::-1] results in “nohtyP.” · # Define a sample ...