For example,
str = "hello"
str[1::3]
And where can I find this in Python documentation?
For example,
str = "hello"
str[1::3]
And where can I find this in Python documentation?
s[i:j:k] slice of s from i to j with step k
The slice of
s
fromi
toj
with stepk
is defined as the sequence of items with indexx = i + n*k
such that0 <= n < (j-i)/k
. In other words, the indices arei
,i+k
,i+2*k
,i+3*k
and so on, stopping whenj
is reached (but never includingj
). Ifi
orj
is greater thanlen(s)
, uselen(s
). Ifi
orj
are omitted orNone
, they become “end” values (which end depends on the sign ofk
). Note,k
cannot be zero. Ifk
isNone
, it is treated like 1.