Python remove the last character from a string

410    Asked by ranjan_6399 in Python , Asked on Apr 14, 2021

Let's say my string is 10 characters long.

How do I remove the last character?

If my string is "abcdefghij" (I do not want to replace the 'j' character, since my string may contain multiple 'j' characters) I only want the last character gone. Regardless of what it is or how many times it occurs, I need to remove the last character from my string.

Answered by Ranjana Admin

To remove the last character from a Python string you can use the below-mentioned code:-

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

Your Answer

Interviews

Parent Categories