Since this works even on empty strings, it's a pretty safe way of removing that last character, if present: >>> ''[:-1] ''. This works on any sequence, not just strings. For lines in a text file, I’d actually use line.rstrip('\n') to only remove a newline; sometimes the last line in the file doesn’t end in a newline character and using ... More @Wikipedia
Hover over any link to get a description of the article. Please note that search keywords are sometimes hidden within the full article and don't appear in the description or title.