Question 2
Back to Exercise
What is the output of the following Python program?
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!