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-get-last-n-characters-of-a-string
Get Last N characters of a string - Python - GeeksforGeeks
July 23, 2025 - String slicing is the fastest and most straightforward way to get the last N characters from a string. Itโ€™s built into Python and highly optimized for such tasks.
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ last-character-string-python
Get the Last Character of a String in Python - Flexiple
To get the last character of a ... a string, including individual characters. To get the last character, you can use the slice [-1:], which includes the last character up to the end of the string....
๐ŸŒ
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 - # Basic slicing word = "Python!" without_last = word[:-1] # Returns "Python" # Works with empty strings empty = "" result = empty[:-1] # Returns "" (empty string) # Works with single characters single = "A" result = single[:-1] # Returns "" (empty string) String slicing is memory-efficient because Python optimizes string slices under the hood.
๐ŸŒ
Jeremy Morgan
jeremymorgan.com โ€บ python โ€บ how-to-get-the-last-character-of-a-string-python
How to Get the Last Character of a String in Python
December 11, 2023 - We can use slicing with a step size of -1 to get the last character of a string. ... Since Python strings are immutable we canโ€™t reverse the string in place like we can with other languages.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-get-the-last-n-characters-of-a-string-in-python
How to Get the Last N characters of a String in Python
March 27, 2026 - def get_last_n_characters(text, n): slice_obj = slice(-n, None) return text[slice_obj] text = "Hello, world!" n = 5 result = get_last_n_characters(text, n) print(f"Last {n} characters: {result}") # Reusing the slice object last_3 = slice(-3, None) print("Python"[last_3]) # hon print("Programming"[last_3]) # ing ... The deque with maxlen parameter automatically maintains only the last N elements, making it memory-efficient for large strings.
๐ŸŒ
Thequantizer
thequantizer.com โ€บ the quantizer โ€บ python
Python: How to Get the Last Character in a String :: The Quantizer
In Python the first number of the slice is the start and the last number is where python stops slicing exclusively. This is important to pay attention to the inclusive start index and the exclusive end index. If you are getting one too many or too few characters with a slice it is probably ...
Find elsewhere
๐ŸŒ
Real Python
realpython.com โ€บ python-strings
Strings and Character Data in Python โ€“ Real Python
December 22, 2024 - As with any slicing, the first and second indices can be omitted and default to the first and last characters, respectively: ... >>> numbers = "12345" * 5 >>> numbers '1234512345123451234512345' >>> numbers[::5] '11111' >>> numbers[4::5] '55555' In the first slicing, you omit the first and second indices, making the slice start at index 0 and go up to the end of the string.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ string-slicing-in-python
String Slicing in Python - GeeksforGeeks
Return Type: The result of a slicing ... indexing is useful for accessing elements from the end of the String. The last element has an index of -1, the second last element -2 and so on....
Published ย  July 12, 2025
๐ŸŒ
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 ... 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....
๐ŸŒ
101 Computing
101computing.net โ€บ home โ€บ python challenges โ€บ string slicing in python
String Slicing in Python - 101 Computing
August 12, 2024 - If start is left empty, the substring will start from position 0. If end is left empty, the substring will end at the last character of the string. A negative start value or end value is used to identify a position (number of characters) from ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-remove-last-n-characters-from-a-string
Python program to remove last N characters from a string - GeeksforGeeks
July 23, 2025 - By leveraging slicing, we can easily remove the last N characters from a string with minimal code. ... s[:-n] slices the string from the start to the position len(s) - n, effectively removing the last N characters.
๐ŸŒ
Python Pool
pythonpool.com โ€บ home โ€บ blog โ€บ 5 ways to remove the last character from string in python
5 Ways to Remove the Last Character From String in Python - Python Pool
January 3, 2024 - We can remove or delete the last character from the string by accessing the given stringโ€™s positive index. Let us look at the example for a better understanding of the concept: #python slicing using positive index Str = "Latracal Solutionss" l = len(Str) Remove_last = Str[:l-1] print("String : ",Remove_last)
๐ŸŒ
PyTaster
pytaster.com โ€บ remove-the-first-and-last-character-of-a-python-string
Remove First and Last Character from Python String | PyTaster
July 4, 2025 - Letโ€™s take a look at a few examples, just to make sure we understand how reverse indexing works in Python. ... #creating a few strings for us to work with string1 = 'simple_string' string2 = 'A bit more complex.' string3 = 'It was the best of times, it was the worst of times' #finding and printing the last character of each string print('The last character of String 1 is: ' + string1[-1]) print('The last character of String 2 is: ' + string1[-1]) print('The last character of String 3 is: ' + string1[-1])
๐ŸŒ
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.
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ article โ€บ how-to-get-the-last-n-characters-of-a-string-in-python
How To Get The Last N Characters Of A String In Python
July 27, 2023 - In this method we will use negative slicing i.e. we will be printing the value stored at the -1 index of the demo string. ... In the same way, you can print N last characters of a String.