What is the purpose of the two colons in this Python string-slicing statement?

↘锁芯ラ 提交于 2019-12-23 07:02:57

问题


For example,

str = "hello"
str[1::3]

And where can I find this in Python documentation?


回答1:


in sequences' description:

s[i:j:k]    slice of s from i to j with step k

The slice of s from i to j with step k is defined as the sequence of items with index x = i + n*k such that 0 <= n < (j-i)/k. In other words, the indices are i, i+k, i+2*k, i+3*k and so on, stopping when j is reached (but never including j). If i or j is greater than len(s), use len(s). If i or j are omitted or None, they become “end” values (which end depends on the sign of k). Note, k cannot be zero. If k is None, it is treated like 1.



来源:https://stackoverflow.com/questions/1013272/what-is-the-purpose-of-the-two-colons-in-this-python-string-slicing-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!