【发布时间】:2020-11-08 04:13:57
【问题描述】:
切片的默认范围是多少: 例如:
ls = [1, 2, 3, 4, 5]
ls[-3::1] #returns copy of the elements at indexes -3, -2, -1
ls[-3::-1] #returns copy of the elements at indexes -3 till the start of the list i.e ls[-5]
ls[::-1] #returns copy of the reverse version of the list
ls[::1] #return the list as is
这背后的想法是什么? python如何确定未说明的开始和结束索引?
【问题讨论】:
-
如果你有一个积极的步骤,那么默认开始是开始,默认结束是结束。如果您有一个负步骤,则默认开始是结束,默认结束是开始。默认步长为 1。
-
很高兴您决定询问社区,但您可以在官方文档中轻松找到此信息。那么,有什么意义呢?
标签: python python-3.x string list python-2.7