Please explain how we got this output

please explain how we got this output
(4,-2) both are same index
a = [‘foo’, ‘bar’, ‘baz’, ‘qux’, ‘quux’, 'corg]
print(a[4::-2])

output:[‘quux’, ‘baz’, ‘foo’]

1 Like

you have mentioned a[4 : : 2 ]
so this means = a [ start position : where to end : gap ]
so it will start from 4 th index . i.e quux and it will go in reverse direction and will skip -2 .
Therefore the output will start from "quux " it will skip -2 and print " baz " then “foo”

1 Like

thank you for the explanation

2 Likes