LearnFrenzy
Sign in Take a free test

Strings · Predict the Output · Question 2

Slices with steps Answer, explanation & discussion

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

What is the output of the following Python program?

main.py
s = "abcdef"
print(s[::2], s[::-1], s[-3:], s[4:1:-1])
  • A ace fedcba def edc Correct
  • B ace fedcba def dcb
  • C bdf fedcba def edc
  • D ace abcdef cde edc
Correct Answer: Option A

s[4:1:-1] starts at index 4 ("e") and walks backwards, stopping before index 1: e, d, c.

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