Apr-27-2020, 08:14 PM

Hello everyone, I have a simple question about sequence slicing and do not get why the following happens, please help me with that:

A very simple question:

The operation numbers[:5:-2] means I get [1, 2, 3, 4, 5] from the 1. Part(numbers[:5]), and then from the end to the beginning get every second element([1, 2, 3, 4, 5]) backwards, so I should get [5, 3, 1], why the result is [10, 8]?

Please point out where I understand wrong.

Thanks.

A very simple question:

>>> numbers=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> numbers[:5:-2] [10, 8]I am very confused about this result. Here is what I thought should happen:

The operation numbers[:5:-2] means I get [1, 2, 3, 4, 5] from the 1. Part(numbers[:5]), and then from the end to the beginning get every second element([1, 2, 3, 4, 5]) backwards, so I should get [5, 3, 1], why the result is [10, 8]?

Please point out where I understand wrong.

Thanks.