下标序列时,Python 中的 ::(双冒号)是什么? [英] What is :: (double colon) in Python when subscripting sequences?

查看:79
本文介绍了下标序列时,Python 中的 ::(双冒号)是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用诸如 string[3:4] 之类的东西在 Python 中获取子字符串,但是 somesequence[::3]?

I know that I can use something like string[3:4] to get a substring in Python, but what does the 3 mean in somesequence[::3]?

推荐答案

它的意思是第一个参数什么都没有,第二个参数什么都没有,然后跳三个".它对序列的每第三个项目进行切片.扩展切片正是您想要的.Python 2.3 中的新功能

it means 'nothing for the first argument, nothing for the second, and jump by three'. It gets every third item of the sequence sliced. Extended slices is what you want. New in Python 2.3

这篇关于下标序列时,Python 中的 ::(双冒号)是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆