I am trying to remove the first and last characters in a given string in python.
I want the if statement to replace the letter with an empty string, as the last line is attempting. But i is a str and not an int, so I cant use it to find the index in the replace function. I need some way to access the number of iterations to the string, and not the string letter itself, is there a simple thing I'm missing here?
def without_end(str):
first = str[0]
last = str[-1]
for i in str:
if i == first or i == last:
new_string = str.replace(str[i], "")
return new_string