Solved Why does the end index not include the character? CHCharlieHOP 3 Oct, 07:59 Slices "stop before" the end index. Why was it designed like this?
HEHenryWrites3 Oct, 15:19 Solutionreplies: 1It makes many things simpler: s[:n] has exactly n characters, s[a:b] has b - a characters, and s[:i] + s[i:] always gives back the whole string. Once it clicks, it's very convenient.
SOSophieDev3 Oct, 17:08Stage 2's dash_index and last_index make you look at the actual positions. Helps a lot.
SASamPrice3 Oct, 22:53Off-by-one errors: one of the two hard problems in computer science (along with naming things and cache invalidation) š
Comments 4
Join the discussion CommentAlready have an account? Log in
It makes many things simpler:
s[:n]has exactly n characters,s[a:b]has b - a characters, ands[:i] + s[i:]always gives back the whole string. Once it clicks, it's very convenient.s[:i] + s[i:]is a great way to remember it.Stage 2's dash_index and last_index make you look at the actual positions. Helps a lot.
Off-by-one errors: one of the two hard problems in computer science (along with naming things and cache invalidation) š