# List Slicing doesn't work as expected

**URL:** <https://forum.codewithmosh.com/t/list-slicing-doesnt-work-as-expected/20477>\
**Category:** Python\
**Created:** [May 26, 2023, 7:23am UTC](https://forum.codewithmosh.com/t/list-slicing-doesnt-work-as-expected/20477 "2023-05-26T07:23:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bidhan](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@Bidhan](https://forum.codewithmosh.com/u/Bidhan)\
**Post date:** [May 26, 2023, 7:23am UTC](https://forum.codewithmosh.com/t/list-slicing-doesnt-work-as-expected/20477/1 "2023-05-26T07:23:59Z")

</div>

l = [1,2,3,4,5,6,7,8,9]  
print(l[:4:-1])

what my logic says is - start from 0 th position i.e value 1, and need to start move left (as the step is -1) and stop when I get index 4, so python doesn’t get index 4 while he started moving left direction, so it should not print anything in output, but the output is - [9, 8, 7, 6]  
Can somebody please explain how this works?  
Thanks,  
Bidhan

---

<div class="post-metadata">

**Author:** ![Juvelix](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/juvelix/32/6169_2.png) [@Juvelix](https://forum.codewithmosh.com/u/Juvelix)\
**Post date:** [May 26, 2023, 8:55am UTC](https://forum.codewithmosh.com/t/list-slicing-doesnt-work-as-expected/20477/2 "2023-05-26T08:55:17Z")

</div>

In Python slicing, the notation **start:stop:step** is used to define the range of indices to extract from a sequence. The range includes the start index but excludes the stop index.

In your case, when using a negative step value, such as **-1** in "**[:4:-1]**, the start and stop indices are reversed. This means that the start index becomes greater than the stop index.  
In **[:4:-1]** starts from index `4` and iterates towards the beginning of the list in reverse order, but the start index is excluded in the iteration.

Example:  
Number[Index]  
1[0],2[1],3[2],4[3],5[4] ,6[5],7[6],8[7],9[8]  
Index[4] = 5 so it the iteration excludes 5 and the result is as you said [9, 8, 7, 6]
