Simple:

my_str =  "abcdefghij"
my_str = my_str[:-1]

Try the following code snippet to better understand how it works by casting the string as a list:

str1 = "abcdefghij"
list1 = list(str1)
print(list1)
list2 = list1[:-1]
print(list2)

In case, you want to accept the string from the user:

str1 = input("Enter :")
list1 = list(str1)
print(list1)
list2 = list1[:-1]
print(list2)

To make it take away the last word from a sentence (with words separated by whitespace like space):

str1 = input("Enter :")
list1 = str1.split()
print(list1)
list2 = list1[:-1]
print(list2)
Answer from Cyrille on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-remove-last-character-from-the-string
Python program to Remove Last character from the string - GeeksforGeeks
July 11, 2025 - ... Str = "GeeksForGeeks" # Using positive indexing print(Str[:len(Str) - 1]) Str = "GeeksForGeeks" # Using negative indexing print( Str[:-1]) ... Str[:len(Str) - 1] removes last character by slicing up to second last index.
Discussions

5 Ways You Can Remove Last Character From String in Python
Method 1 and 2 are the same, except that defining a variable that doesn't do anything but hold the length of string 1 is even a bit more inefficient than method 1. Importing the re module to remove a character from a string is just ridiculous. Also it's not removing the last character, but deleting all 'n's. Could have achieved the same with the built-in str.replace() method. str.rstrip() isn't used correctly. It won't remove the last character, but will also shorten 'helloooooo' to 'hell'. The loop also removes all 'n's, not necessarily the last character. Plus it is highly inefficient and not pythonic in any way More on reddit.com
🌐 r/programming
3
0
July 19, 2021
regex - How can I remove the last character of a string in python? - Stack Overflow
I have a file path as a string and trying to remove the last '/' from the end. my_file_path = '/home/ro/A_Python_Scripts/flask-auto/myDirectory/scarlett Johanson/1448543562.17.jpg/' I've been tryi... More on stackoverflow.com
🌐 stackoverflow.com
How to remove last two characters from strings under a Dataframe column
You can use the str() method in Pandas to remove the last 2 characters from all values in a particular column: df["Index"] = df["Index"].str[:-2] More on reddit.com
🌐 r/learnpython
4
1
June 13, 2022
Why is the list method which returns all but the last element named init?

Just some observations:

  • head, tail, init, last are all four-character words

  • Haskell uses these same operations

  • Erlang also seems to use these terms

  • Okasaki's book/thesis also contains these, language is Standard ML

Scala borrowing from these functional languages (particularly ML and Haskell), my guess is the terminology was inspired from these.

More on reddit.com
🌐 r/scala
7
6
December 11, 2015
People also ask

How do I remove the last character from a Python string?
Use text[:-1], which returns a new string without the final character and safely returns an empty string for empty or one-character input.
🌐
pythonpool.com
pythonpool.com › home › tutorials › remove the last character from a python string safely
5 Ways to Remove the Last Character From String in Python
Can Python strings be changed in place?
No. Strings are immutable, so save the result of slicing or removesuffix() in a new variable or return it from a helper.
🌐
pythonpool.com
pythonpool.com › home › tutorials › remove the last character from a python string safely
5 Ways to Remove the Last Character From String in Python
How do I remove only a trailing newline?
Use text.removesuffix('\n') so real content is not removed when the final line does not contain a newline.
🌐
pythonpool.com
pythonpool.com › home › tutorials › remove the last character from a python string safely
5 Ways to Remove the Last Character From String in Python
🌐
Career Karma
careerkarma.com › blog › python › python: remove last character from string
Python: Remove Last Character from String | Career Karma
December 1, 2023 - Slicing syntax lets you delete the last character from a string object in Python. All you need to do is specify a string and add [:-1] after the string. Now you’re ready to remove the last character from a Python string like an expert!
🌐
Geekflare
geekflare.com › development › how to remove last character from python string?
How to Remove Last Character from Python String?
January 20, 2025 - We don’t have to write more than a line of code to remove the last char from the string. Give the last element to the strip method, it will return the string by removing the last character.
🌐
Medium
medium.com › @ryan_forrester_ › remove-the-last-character-from-a-string-in-python-a16000d6c102
Remove the Last Character from a String in Python | by ryan | Medium
January 7, 2025 - String slicing is memory-efficient because Python optimizes string slices under the hood. It’s also very readable — even newer Python developers can quickly understand what `[:-1]` does. The `slice()` function offers more flexibility when you need to store or reuse the slicing pattern: # Creating a reusable slice remove_last = slice(None, -1) text = "Hello World!" result = text[remove_last] # Returns "Hello World" # Reuse the same slice on different strings names = ["John!", "Mary!", "Steve!"] clean_names = [name[remove_last] for name in names] # Returns ['John', 'Mary', 'Steve']
🌐
Reddit
reddit.com › r/programming › 5 ways you can remove last character from string in python
r/programming on Reddit: 5 Ways You Can Remove Last Character From String in Python
July 19, 2021 - For example let's say you want to remove a .git suffix. This seems to work okay: "https://github.com/username/reponame.git".rstrip(".git") # https://github.com/username/reponame · Works great, right? Not so fast... "https://github.com/username/gog.git".rstrip(".git") # https://github.com/username/go · eek, not what we wanted! So in practice I always use re.sub, which you can be much more specific to specify start/end of the string, and exactly what to replace.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-remove-last-character-in-list-of-strings
Python | Remove last character in list of strings - GeeksforGeeks
May 18, 2023 - The map function can perform the task of getting the functionality executed for all the members of list and lambda function performs the task of removal of last element using list comprehension. ... # Python3 code to demonstrate # remove last character from list of strings # using map() + lambda # initializing list test_list = ['Manjeets', 'Akashs', 'Akshats', 'Nikhils'] # printing original list print("The original list : " + str(test_list)) # using map() + lambda # remove last character from list of strings res = list(map(lambda i: i[: -1], test_list)) # printing result print("The list after removing last characters : " + str(res))
🌐
Python Pool
pythonpool.com › home › tutorials › remove the last character from a python string safely
5 Ways to Remove the Last Character From String in Python
July 13, 2026 - It is simple, fast, and familiar to Python readers. A small helper keeps the behavior consistent when several places need the same cleanup. It also gives you one place to enforce that the input is a string. def remove_last_char(text): if not isinstance(text, str): raise TypeError("text must be a string") return text[:-1] for item in ["report.csv", "A", ""]: print(repr(remove_last_char(item)))
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python remove last character from string
Python Remove Last Character From String - Spark By {Examples}
May 21, 2024 - How to remove the last character from a string in Python? String manipulation is indeed one of the most important features of Python, and knowing various
🌐
Python Guides
pythonguides.com › remove-the-last-character-from-a-string-in-python
Remove Last Character from String in Python
August 20, 2025 - The most common way I remove the last character from a string is by using slicing. Python strings are sequences, so slicing works perfectly.
🌐
w3resource
w3resource.com › python-exercises › basic › python-basic-1-exercise-123.php
Python: Remove the first and last elements from a given string - w3resource
# Define a function 'test' that removes the first and last characters from a string. def test(input_str): # Return the original string if its length is less than 3, otherwise return the string excluding the first and last characters. return input_str if len(input_str) < 3 else input_str[1:-1] # Test the 'test' function with different input strings. str1 = "PHP" print("Original string: ", str1) print("Removing the first and last elements from the said string: ", test(str1)) str2 = "Python" print("\nOriginal string: ", str2) print("Removing the first and last elements from the said string: ", test(str2)) str3 = "JavaScript" print("\nOriginal string: ", str3) print("Removing the first and last elements from the said string: ", test(str3))
🌐
Delft Stack
delftstack.com › home › howto › python › how to remove last character from string in python
How to Remove the Last Character From String in Python | Delft Stack
February 2, 2024 - Python provides the support to remove the last character from string and a specific number of characters by using the slicing method, for() loop, and regex method.
🌐
Plain English
plainenglish.io › home › blog › python › 5 ways you can remove the last character from a string in python
5 Ways You Can Remove the Last Character from a String in Python
June 2, 2021 - Using the regular expression method we can easily remove the last character from the string. For using the regular expression method, you need to import the re library. For a better understanding, let’s look into the example. ... import re str1 = "This is python" print ("original string is:", str1) str2 = re.sub("n","", str1) print ("after removing the last character, the string is:", str2)
🌐
TutorialsPoint
tutorialspoint.com › article › python-program-to-remove-the-last-specified-character-from-the-string
Python Program to remove the last specified character from the string
June 1, 2023 - This operation is useful for data cleaning, input validation, and string formatting. Python provides several approaches including slicing, rstrip(), and string replacement methods. String slicing with [:-1] removes the last character by excluding it from the slice ?
🌐
Codecademy
codecademy.com › article › remove-characters-from-a-python-string
How to Remove Characters from a String in Python | Codecademy
String slicing is a useful feature in Python that enables us to extract a portion of a string using index positions. We can use this feature to remove the last character from a string.
🌐
datagy
datagy.io › home › python posts › python strings › how to remove first or last character from a python string
How to Remove First or Last Character From a Python String • datagy
December 16, 2022 - This provides simplifies the process ... remove the last character from a Python string, we can slice the string up to the last character and assign the string back to itself....
🌐
CodeRivers
coderivers.org › blog › python-delete-last-element-of-string
Python: Deleting the Last Element of a String - CodeRivers
February 22, 2026 - Slicing is a powerful feature in Python that allows you to extract parts of a sequence, such as a string. To delete the last element of a string using slicing, you can create a new string that includes all characters from the start of the original string up to, but not including, the last character.
🌐
Linux Hint
linuxhint.com › remove-last-character-from-string
Linux Hint – Linux Hint
May 14, 2023 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Career Karma
careerkarma.com › blog › python › python remove character from string: a guide
Python Remove Character from String: A Guide | Career Karma
December 1, 2023 - We are using a Python list ... we specified from our string. To remove the last character from a string, use the [:-1] slice notation....