Return last character of string in python
The last character of every line is a newline character. You can strip it:
print(line.strip()[-1])
# or print(line.rstrip()[-1])
Simple, take the string and clear it's leading and trailing spaces. Then return the last character in your case. Otherwise simply return last character.
line=line.strip()
return line[-1]