Solved

Why does the end index not include the character?

CharlieHOP

Slices "stop before" the end index. Why was it designed like this?

8

Comments 4

Join the discussion

Already have an account? Log in

  1. HenryWrites Solutionreplies: 1

    It 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.

    2
    1. SophieDev

      Stage 2's dash_index and last_index make you look at the actual positions. Helps a lot.

      3
      1. SamPrice

        Off-by-one errors: one of the two hard problems in computer science (along with naming things and cache invalidation) šŸ˜„

        4