list[x::y] 有什么作用? [英] What does list[x::y] do?
本文介绍了list[x::y] 有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
Python 切片表示法的优秀入门
我最近阅读了一些示例代码,也阅读了很多网站,但我似乎无法正确查询以提供我正在寻找的答案.如果有人可以帮助我,我将不胜感激.
I've been reading over some sample code lately and I've read quite a few websites but I just can't seem to get the query right to give me an answer I'm looking for. If anyone could help me out I'd appreciate it.
推荐答案
It slices
x[startAt:endBefore:skip]
如果您使用 skip = 2
,则列表中以 startAt
开始并以 endBefore
结束的所有其他元素都将被选中.[记住:索引存在于列表元素之间]
if you use skip = 2
, every other element the list beginning at startAt
and ending at endBefore
will be selected. [Remember: indices live BETWEEN list elements]
要查看此内容,请输入
x = range(100)
在 Python 提示符下.那就试试这些吧
at the Python prompt. Then try these things
x[::2]
x[::3]
x[10:40:6]
看看会发生什么.
这篇关于list[x::y] 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文