For example,
str = "hello"
str[1::3]
And where can I find this in Python documentation?
In Python, a colon is required at the beginning of every block of code. It is easier to explain with an example. Notice how at the end of the if statement I have a colon. This tells Python that the next line of indented code should only be run IF the condition is true.
Artturi Jalli. In Python, [::-1] means reversing a string, list, or any iterable with an ordering. For example: hello = "Hello world"
The double colon ( :: ) may refer to: an analogy symbolism operator, in logic and mathematics. a notation for equality of ratios. a scope resolution operator, in computer programming languages.
Consider a python list, In-order to access a range of elements in a list, you need to slice a list. One way to do this is to use the simple slicing operator i.e. colon(:) With this operator, one can specify where to start the slicing, where to end, and specify the step.
in sequences' description:
s[i:j:k] slice of s from i to j with step k
The slice of
sfromitojwith stepkis defined as the sequence of items with indexx = i + n*ksuch that0 <= n < (j-i)/k. In other words, the indices arei,i+k,i+2*k,i+3*kand so on, stopping whenjis reached (but never includingj). Ifiorjis greater thanlen(s), uselen(s). Ifiorjare omitted orNone, they become “end” values (which end depends on the sign ofk). Note,kcannot be zero. IfkisNone, it is treated like 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With