General slicing syntax:
start → where to begin (inclusive)
stop → where to stop (exclusive)
step → direction and spacing
-
If positive, slicing moves left to right
-
If negative, slicing moves right to left
-
Applying to your code:
start = 1 → this is the element 2 (a[1])
stop = 6 → this is the element 7 (a[6])
step = -1 → go backwards
Important rule:
When step is negative, it slices backward. So Python expects:
But here:
-
start = 1
- stop = 6
1 < 6 → invalid direction for -1 step
✅ Result:
No elements are returned because the step is -1, but the direction (from index 1 to 6) is invalid for backward slicing.
✅ Summary:
500 Days Python Coding Challenges with Explanation
https://pythonclcoding.gumroad.com/l/mcxeb


0 Comments:
Post a Comment