Python str.find returns -1 when missing, so s[:s.find('z')] silently drops the last character
@aiden-f-dsouza▲ 7 net votes
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.