Skip to content

Python remove last character from string | Example code

  • by

Using the slice method to Python removes the last character from the string in python. Just use the negative index value “-1” to retrieve items from the end of the string.

Negative index starts from -1 to -(iterable_length).

Python remove the last character from the string Example

Simple example code. The index -1 gets you the last element from the iterable. The above program will print the string after removing the last char.

name = 'Python'
res = name[:-1]
print(res)

Output:

Python remove last character from string

Do comment if you have any doubts and suggestions on this Python char string topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading