Normally, you would just do:

Use with AIs = 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
๐ŸŒ
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): b = "Hello, World!" print(b[2:5]) Try it Yourself ยป ยท Python Strings Tutorial String Literals Assigning a String to a Variable Multiline Strings Strings are Arrays Negative Indexing on a String String Length Check In String Format String Escape Characters
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ string-slicing-in-python
String Slicing in Python - GeeksforGeeks
String slicing is a way to get specific parts of a string by using start, end and step values. Itโ€™s especially useful for text manipulation. ... Explanation: Here, we used the slice s[0:5] to obtain the substring "Hello" from the original string.
Published: October 7, 2026
๐ŸŒ
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
When constructing a slice, as in [6:11], the first index number is where the slice starts (inclusive), and the second index number is where the slice ends (exclusive), which is why in our example above the range has to be the index number that would occur just after the string ends.
๐ŸŒ
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.
๐ŸŒ
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:
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ string-slicing-in-python
String Slicing in Python: A Complete Guide | LearnPython.com
April 15, 2024 - Another way of slicing a string in Python is the slice() function. It returns a slice object representing the set of indices specified by start, stop, and step parameter. Slice objects contain a portion of a sequence.
๐ŸŒ
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 - Python string indexing can also be used to extract a substring from a larger string. This process is referred to as slicing. To use Python to slice a string from a parent string, indicate the range of the slice using a start index and an end index.
Find elsewhere
๐ŸŒ
Python Central
pythoncentral.io โ€บ cutting-and-slicing-strings-in-python
Cutting and slicing strings in Python - Python Central
September 6, 2023 - The simplest way of extracting single characters from strings (and individual members from any sequence) is to unpack them into corresponding variables. [python] >>> s = 'Don' >>> s 'Don' >>> a, b, c = s # Unpack into variables >>> a 'D' >>> b 'o' >>> c 'n' [/python]
๐ŸŒ
Python Guides
pythonguides.com โ€บ slicing-string-in-python
How to Perform String Slicing in Python
September 16, 2025 - The general syntax for slicing in Python looks like this: ... This simple structure gives us a lot of flexibility when working with strings. The most common way I use slicing is by specifying the start and end indices. This is useful when you know exactly which part of the string you want.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-substring-how-to-slice-a-string
Python Substring โ€“ How to Slice a String
July 27, 2021 - Here you use the negative index to start slicing from the end of the string. ... The output will be โ€˜campโ€™. You can slice the string with steps after indicating a start-index and stop-index.
๐ŸŒ
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.
๐ŸŒ
Real Python
realpython.com โ€บ lessons โ€บ string-slicing
String Slicing (Video) โ€“ Real Python
Join us and get access to thousands of tutorials and a community of expert Pythonistas. ... In the previous lesson, you saw how you could access individual characters in a string using indexing. In this lesson, youโ€™ll learn how to expand that syntax to extract substrings from a string. This technique is known as string slicing. Youโ€™ll practice with the standard syntax, and learn how omitting the first or last index extends the slice.
Published: October 1, 2019
๐ŸŒ
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 - Learn how to index and slice strings in Python 3 with step-by-step examples. Master substring extraction, negative indexing, and slice notation.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ string slicing in python
String Slicing in Python
October 22, 2024 - The slice() method is particularly useful when you need to apply the same slice to multiple strings or in scenarios where you want to keep your code organized and readable. Python's List/Array slicing method is a concise and powerful way to slice strings.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ slice
Python slice() | Programiz
March 14, 2024 - In this tutorial, we will learn about the Python slice() function with the help of examples. The slice() function returns a slice object that is used to slice any sequence (string, tuple, list, range, or bytes).
๐ŸŒ
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
๐ŸŒ
CodingNomads
codingnomads.com โ€บ string-slicing-in-python
String Slicing in Python
String slicing in Python is when you extract a sub-string from it's parent string. Removing 'age' from 'cottage' is an example of string splicing.