1st Aug 2022, 7:50 AM
Shiva Kumar
Shiva Kumar - avatar
2 Respuestas
+ 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.
1st Aug 2022, 8:32 AM
Ipang
+ 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])
1st Aug 2022, 9:09 AM
Solo
Solo - avatar