Sunday 12 November 2017

syntax - What is :: (double colon) in Python when subscripting sequences?

itemprop="text">

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]?



Answer




it means 'nothing for the first argument,
nothing for the second, and jump by three'. It gets every third item of the sequence
sliced.
href="http://docs.python.org/release/2.3.5/whatsnew/section-slices.html">Extended
slices is what you want. New in Python 2.3



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...