Normally, you would just do:

s = s[:-3] + s[-2:]

The s[:-3] gives you a string up to, but not including, the comma you want removed ("this is a string") and the s[-2:] gives you another string starting one character beyond that comma (" a").

Then, joining the two strings together gives you what you were after ("this is a string a").

Answer from Anurag Uniyal on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › string-slicing-in-python
String Slicing in Python - GeeksforGeeks
String slicing in Python is a way to get specific parts of a string by using start, end and step values. It’s especially useful for text manipulation and data parsing. ... Explanation: In this example, we used the slice s[0:5] to obtain the ...
Published: July 12, 2025
🌐
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 Training ... You can return a range of characters by using the slice syntax.
Discussions

String slicing in Python script
In my client startup script I am trying to capture the first four characters of the PC name with this script HostName1 = system.tag.readBlocking('[System]Client/Network/Hostname') # Grab the whole host name, Should be EVRZ-HMI-NBurn for example. print HostName1 HostPref = HostName1[0:3] # just ... More on forum.inductiveautomation.com
🌐 forum.inductiveautomation.com
11
0
January 12, 2024
Python strings slicing - Stack Overflow
I find it interesting that s[0:-5:-1] ... empty string '', that was unexpected. It looks like you tried to explain why but I'm not following. 2022-09-27T18:32:05.42Z+00:00 ... Save this answer. ... Show activity on this post. Slicing is used with [start:stop:step]. If you use negative numbers for start it will start at the specified index, from the end. If you want to print "Savi", I think you must have to slices ... More on stackoverflow.com
🌐 stackoverflow.com
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
Doubt in String Slicing
Hello Everyone, I am having a doubt regarding String Slicing, so what I actually need is that for an example if the word “Happy” is the actual content and I need to work with String slicing as that I need to print with required following output as H y Ha py Hap ppy Happ appy Happy Happy ... More on discuss.python.org
🌐 discuss.python.org
10
0
July 7, 2022
🌐
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:
🌐
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 Training ... You can return a range of characters by using the slice syntax.
🌐
freeCodeCamp
freecodecamp.org › news › slicing-and-indexing-in-python
Slicing and Indexing in Python – Explained with Examples
December 11, 2025 - In these examples, we have used slicing to extract a range of characters from the sentence string. The 4:9 slice means that we are selecting characters starting from index 4 (inclusive) up to index 9 (exclusive), which correspond to the second word "quick".
Find elsewhere
🌐
Akamai
akamai.com › cloud › guides › how-to-slice-and-index-strings-in-python
How to Slice and Index Strings in Python | Linode Docs
January 28, 2022 - String slicing is a powerful operation for creating a substring from the original string. In addition to extracting a string consisting of consecutive characters, a string slice can select every nth letter or even work in reverse.
🌐
Inductive Automation
forum.inductiveautomation.com › ignition
String slicing in Python script - Ignition - Inductive Automation Forum
January 12, 2024 - In my client startup script I am trying to capture the first four characters of the PC name with this script HostName1 = system.tag.readBlocking('[System]Client/Network/Hostname') # Grab the whole host name, Should be EVRZ-HMI-NBurn for example. print HostName1 HostPref = HostName1[0:3] # just grab the first four characters, this is an example of String Slicing. print HostPref print "Hello dummy" print HostName1[:3] According to the help, the string slice of HostName1[0:3] should work....
🌐
CodeHS
codehs.com › tutorial › 13739
Tutorial: Slicing Python Strings | CodeHS
Click on one of our programs below to get started coding in the sandbox
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › brackets › slicing.html
[] (slicing) — Python Reference (The Right Way) 0.1 documentation
The last index of the slice or the number of items to get. Defaults to len(sequence). step · Optional. Extended slice syntax. Step value of the slice. Defaults to 1. The same as selected. O(k) for slice retrieval · O(n) for deletion · O(n+k) for slice assignment · Consider the following ASCII graph showing the contents of the “ABCD” string: >>> +---+---+---+---+ >>> |-4 |-3 |-2 |-1 | <= negative indexes >>> +---+---+---+---+ >>> | A | B | C | D | <= sequence elements >>> +---+---+---+---+ >>> | 0 | 1 | 2 | 3 | <= positive indexes >>> +---+---+---+---+ >>> |<- 0:3:1 ->| <= extent of the slice: "ABCD"[0:3:1] Consider the following example: >>> "ABCD"[0:2] 'AB' It can be read as: get every single one item between indexes 0 and 2 (exclusive).
🌐
Learn By Example
learnbyexample.org › python-string-slicing
Python String Slicing - Learn By Example
April 20, 2020 - # Slice last three characters from the string S = 'ABCDEFGHI' print(S[6:]) # GHI · You can reverse a string by omitting both start and stop indices and specifying a step as -1.
🌐
Medium
medium.com › @kaifraza8329 › string-slicing-and-functions-247e06a5becc
String Slicing And Functions. Information regarding string slicing… | by Kaifraza | Medium
March 7, 2022 - The term ‘string slice’ refers to a part of the string, where strings are sliced using a range of indices. ... In Python, string slicing s[n:m] for a string s is done as characters of s from n to m-1.
🌐
Tutorialspoint
tutorialspoint.com › python › python_slicing_strings.htm
Python Slicing Strings
Python String slicing is a way of creating a sub-string from a given string. In this process, we extract a portion or piece of a string. Usually, we use the slice operator "[ : ]" to perform slicing on a Python String.
🌐
LearnPython.com
learnpython.com › blog › string-slicing-in-python
String Slicing in Python: A Complete Guide | LearnPython.com
April 15, 2024 - In this article, we’ll learn every aspect of slicing a string in Python. Strings are a sequence of characters; slicing allows us to extract a partial sequence from a string. To slice a string in Python, we use character indexes.
🌐
Python.org
discuss.python.org › python help
Doubt in String Slicing - Python Help - Discussions on Python.org
July 7, 2022 - Hello Everyone, I am having a doubt regarding String Slicing, so what I actually need is that for an example if the word “Happy” is the actual content and I need to work with String slicing as that I need to print with required following output as H y Ha py Hap ppy Happ appy Happy Happy ...
🌐
AskPython
askpython.com › python › string › slice-strings-in-python
How to Slice Strings in Python? - AskPython
August 6, 2022 - It is the creation of a new sub-string from the given string on the basis of the user-defined starting and ending indices. If you want to slice strings in Python, it’s going to be as simple as this one line below.
🌐
LeetCode
leetcode.com › problem-list › string
String
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.