One - One Code All

Blog Content

python中双冒号(::)的用法

Python   2008-07-12 08:28:53

语法是:seq[start:end:step]


s[i:j:k]是根据“从i到j与第k步”。何时i和j缺席,整个序列是和s[::k]意思是“每k个项目”。


实例:


>>> s[:10]
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


>>> s[:10:3]
    [0, 3, 6, 9]


上一篇:linux循环执行某条命令
下一篇:python中各种数字类型的判别(numerica, digital, decimal)

The minute you think of giving up, think of the reason why you held on so long.