0
How this [74,85] will come?
2 ответов
+ 3
sk=[1,2,46,77,54,74,85,74,75,54]
print(sk[7:5:-1])
Print slice of list <sk> from index 7 to index 5 (exclusively). The use of -1 specifies that the range goes backward, from greater index (7) to a smaller index (5).
Remember that ranges include the start point and stop at end point - 1. It excludes the end point.
+ 4
ind. 0 1 2 3 4 5 6 7
sk=[1,2,46,77,54,74,85,74,75,54]
print(sk[7:5:-1])
The first two digits indicate the range from 7 to 5, excluding 5, that is, 7, 6. The third digit indicates the counting step.
If it is negative, then the counting goes in the opposite direction and flips the list:
print(sk[7::-1])
That is, similarly to this:
print(sk[6:8:1][::-1])