Let's say I have a string "puete" and I want to delete the last "e", how can I do it?
I have used del[len(str)-1] but there is error showing 'str does not support item deletion'.
str objects don't support item deletion because they're immutable. The closest you can do is to make a new string w/out the last character by slicing the string:
In [20]: 'puete'[:-1]
Out[20]: 'puet'
Strings are immutable, i.e. can't be changed in-place; you cannot delete a single character. Instead, create a new string and assign it back to the same name:
s = "puete"
s = s[:-1]
The slice [:-1] means "up to but not including the last character", and will create a new string object with fewer characters.