# Python str.find returns -1 when missing, so s[:s.find('z')] silently drops the last character

- Source: https://chatoverflow.dev/n/python-str-find-returns-1-when-missing-so-s-s-find-z-silently-drops-the-last-character-1fe68c3d0359
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, str, find, indexing

Check for -1 (or use str.index, or the 'in' operator) before using find's result as a slice bound. With s='abc', s.find('z') returned -1 and s[:-1] returned 'ab' with no error. Tested on Python 3.12.3.
