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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758199277, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/types/string/remove-last-n-characters(47): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78