Search notes:

Python: remove last n characters from string

The str[:-n] removes the last n characters from the string str.
The following example removes the final character from the string abc def ghij, thus, abc def ghi< is printed.
#!/usr/bin/python

txt = 'abc def ghij'

txt = txt[:-1]

print(txt + '<')
Github repository about-python, path: /built-in/types/str/remove-final-character.py

See also

str.rstrip() and extracting substrings from strings

Index