UPDATE: I got code from sololearn.com (freemium site to teach Python). And I ran code on my own Python 3.
I don't understand this output
sqs = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
print(sqs[7:5:-1])
[49, 36]
Is the interpreter skipping 0th element, i.e. 0 and reading list as [1, 4, 9, 16, 25, 36, 49, 64, 81]
, and then printing the 7th element, i.e 49
?
How does it then print 36
? Does it go forward and read [64,81]
, then read backwards [64,49,36]
, hence printing 5th element, i.e. 36
?
If this is correct, then explain following output
>>> print(sqs[7:4:-1])
[49, 36, 25]
I can understand that python skips the 0th element, counts till 7 and prints 49
. But now I specified a gap of 4. So shouldn't the interpreter read [64,81]
, then go in reverse, i.e. [64,49]
, and print 49
? And how did it print 25
?