Python – Delete Last Character from String

Delete Last Character from String

Given a string myStr, we need a string created from the string myStr but without the last character.

To delete the last character from a string in Python, we can use string slicing technique. Specify the ending position as -1, and do not specify the starting position. The slice operation must return the string without the last character.


The syntax of the expression to get the string myStr without last character using slicing is



In the following program, we take a string in myStr and delete the last character.

Python Program

myStr = 'apple'
output = myStr[:-1]

print(f'Input  : {myStr}')
print(f'Output : {output}')
Run Code Copy


Input  : apple
Output : appl


In this tutorial of Python Examples, we learned how to remove the last character from the string using slicing technique, with the help of well detailed examples.

Related Tutorials

Code copied to clipboard successfully 👍