Back to questions
JuniorTheoryCommon
What does the program print?
s = "abcdef"
print(s[1:4], s[::2], s[4:100])bcd ace ef
- Expecting an
IndexErrorfors[4:100]: a slice clamps bounds past the end to the string's length, so it returns what is there,ef. - Expecting
bcdefors[1:4], as if the stop were included: a slice stops beforestop, so it takes indices1,2and3.
- What does
s[::-1]return? - Why does
s[100]raise an error whiles[4:100]does not?