Sunday, July 8, 2018

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



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.
Extended slices is what you want. New in Python 2.3


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...