English subtitles

← Strings Solution - Intro to Computer Science

Get Embed Code
9 Languages

Showing Revision 6 created 05/24/2016 by Udacity Robot.

  1. [Peter] The correct answer for this
  2. is all of them but the second choice.
  3. Let's see why.
  4. Let's pick an example, string s.
  5. Let's say s is duck.
  6. In the first example, we concatenate a with s,
  7. so taking one onwards is going to give us back duck,
  8. which is our original string s.
  9. This works. For the second choice, let's just plug in duck.
  10. The first character, the zeroth character in duck
  11. is going to be d, and we're going to concatenate that
  12. with the rest of the string, giving us back our original string duck.
  13. So this seems like it works, but we have to remember that s
  14. can be the empty string.
  15. If we try taking the character at position 0,
  16. we would get an error because there is no character at position 0
  17. because there are no characters in s.
  18. Moving on, if we try adding an empty string
  19. onto s, we get exactly what we had before because we're not adding anything.
  20. For the last choice, it doesn't seem completely obvious
  21. that it works for the empty string.
  22. It seems unintuitive that taking every character from position 0 onward
  23. would not result in an error because there are no characters.
  24. Well, we have to remember that for the subsequence operator,
  25. this does not cause an error.
  26. Why is that the case? Because.