Why does list[::-1] not equal list[:len(list):-1]?

前端 未结 2 1032
别跟我提以往
别跟我提以往 2021-01-18 06:39

When slicing in python, omitting the end portion of the slice (ie the end in list[:end:]) results in end being define

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-18 07:08

    l[::-1] is the same thing as l.__getitem__(slice(None, None, -1)). Since the start and the stop are both None, the list will be traversed from one end to the other. The step argument determines the direction as well as the step.

提交回复
热议问题