+ 4
What is the Output of this Code?
sqs = [0,1,4,9,16,25,36,49,64,81] print(sqs[5:7:-1]) The answer is [49,36] and its backwards which makes sense with the "-1". But the positions? In each way i am getting 3 elements in the Output..
6 Réponses
+ 4
when it goes backward, the start is the bigger index.
sqs[7:5:-1]
the program first goes to the start, it is 7, counts backward, it is -1, and goes to the stop, it is 5.
syntax for slicing is:
list[start:stop:step]
i hope it helps
+ 3
thanks..
+ 1
Yes but with this Syntax I still get 3 List entries..
0
As explained, the last value is not included in list slicing
0
עז3רקדסג =
0
תודה רבה