You are testing against the string minus the last character:
>>> '"xxx"'[:-1]
'"xxx'
Note how the last character, the "
, is not part of the output of the slice.
I think you wanted just to test against the last character; use [-1:]
to slice for just the last element.
However, there is no need to slice here; just use str.startswith()
and str.endswith()
directly.