why List Slices gives me empty output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why List Slices gives me empty output

squares = [0,1,2,3,4,5,6,7,8,9,10] print(squares[7:5]) output is [] squares = [0,1,2,3,4,5,6,7,8,9,10] print(squares[3:6:-1]) output is []

6th Jun 2017, 11:02 AM
HASSAN AIT BIHI
1 Answer
+ 2
Because there is no output. 7:5 try's to return everything from index 7 to index 5, but it reads from left to right, so 5 is before 7 and your code fails. Try: squares[7:5:-1]
6th Jun 2017, 11:12 AM
Anselm