Question 4
Back to Exercise
Which expression reverses the string s?
- A s[::-1] Correct
- B s.reverse()
- C reverse(s)
- D s[-1:0]
Correct Answer: Option A
A step of -1 walks backwards over the whole string. str has no reverse() method, and s[-1:0] is empty.
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!