LearnFrenzy
Sign in Take a free test

Strings · Predict the Output · Question 3

Slices past the end of a string Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

What is the output of the following Python program?

main.py
s = "hello"
print(repr(s[10:]), len(s[1:100]), s[-100:2])
  • A '' 4 he Correct
  • B IndexError
  • C '' 5 he
  • D None 4 he
Correct Answer: Option A

Out-of-range slice bounds are clipped to the string: s[10:] is empty, s[1:100] is "ello", s[-100:2] is "he".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links