Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sequence slicing problem
#1
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:
>>> 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.
Reply


Messages In This Thread
sequence slicing problem - by qliu - Apr-27-2020, 08:14 PM
RE: sequence slicing problem - by stullis - Apr-27-2020, 09:08 PM
RE: sequence slicing problem - by deanhystad - Apr-27-2020, 09:23 PM
RE: sequence slicing problem - by Yoriz - Apr-27-2020, 09:30 PM
RE: sequence slicing problem - by deanhystad - Apr-27-2020, 09:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  String slicing problem Ollew 4 1,495 Sep-08-2018, 08:07 PM
Last Post: Ollew
  Problem with slicing string YatishK 2 2,154 Apr-24-2017, 09:46 AM
Last Post: YatishK

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020