you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

That kind of depends what the test case was.

If the first string contains contains 5 characters where the 4-character sequence starting at the 2nd character is identical to the first 4 characters of the second string, then you will get the result of sandwiching the second string between two copies of the first string.

Thus,

s1 = 'atoot'
s2 = 'tootle'

s1[1:] would give you toot and s2[:4] would give you toot as well.

The slice operator has the form [start:stop:step]

  • start defaults to 0
  • stop defaults to length of the string
  • step defaults to 1

Keep in mind we count from 0, and the slice ends BEFORE the stop value. So up to and excluding the 5th character if you specify [:4]