Search notes:

Python: taking substrings from a string

A substring can be extracted from a string with brackets. The characters are zero-indexed, so text[n] gets the character at position n+1.
The optional second number (after the colon) is exclusively, so text[n:m] gets the characters at position n+1 through m.
If the numbers are negative, they count from the end of the string towards the beginning.
#!/usr/bin/python3

txt = '0123456789'

print(txt[ 3  ]) # 4th character                - 3
print(txt[ 3:7]) # From 4th to 7th character    - 3456
print(txt[ 7: ]) # From 8th character to end    - 789
print(txt[-2  ]) # 2nd last character           - 8
print(txt[-4: ]) # 4th last character to end    - 6789
Github repository about-python, path: /built-in/types/str/substring.py

See also

str.rstrip() and remove last n characters from a string
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...', 1758199137, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/types/string/substring(58): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78